rethinkdb-java
rethinkdb-java copied to clipboard
improved code smell
Reason for the change Code smell is important for better readability
Description I replaced stuff which can be expressed with isEmpty(). And a try with resource for closing the socket if exception gets thrown
Code examples
I replaced raw.size() == 0
with raw.isEmpty()
more important is the try with resource of the socket.
old code:
SSLSocket sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(
socket,
socket.getInetAddress().getHostAddress(),
socket.getPort(),
true);
// replace input/output streams
inputStream = new DataInputStream(sslSocket.getInputStream());
outputStream = sslSocket.getOutputStream();
// execute SSL handshake
sslSocket.startHandshake();
new code:
try (
SSLSocket sslSocket = (SSLSocket) sslContext.getSocketFactory()
.createSocket(
socket,
socket.getInetAddress().getHostAddress(),
socket.getPort(),
true
)
) {
// replace input/output streams
inputStream = new DataInputStream(sslSocket.getInputStream());
outputStream = sslSocket.getOutputStream();
// execute SSL handshake
sslSocket.startHandshake();
}
Checklist
- [x ] I have read and agreed to the RethinkDB Contributor License Agreement
References Anything else related to the change e.g. documentations, RFCs, etc.