rethinkdb / rethinkdb-java

Official RethinkDB Java client
https://rethinkdb.com/api/java/
Apache License 2.0
21 stars 10 forks source link

improved code smell #63

Open EzxD opened 2 years ago

EzxD commented 2 years ago

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

References Anything else related to the change e.g. documentations, RFCs, etc.