Use try-with-resources

Replace an explicit try-finally by a try-with-resources block.
This commit is contained in:
Romain Vimont 2023-01-27 21:59:26 +01:00
parent 4315be1648
commit b22810b17c

View file

@ -61,8 +61,7 @@ public final class DesktopConnection implements Closeable {
LocalSocket videoSocket; LocalSocket videoSocket;
LocalSocket controlSocket = null; LocalSocket controlSocket = null;
if (tunnelForward) { if (tunnelForward) {
LocalServerSocket localServerSocket = new LocalServerSocket(socketName); try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) {
try {
videoSocket = localServerSocket.accept(); videoSocket = localServerSocket.accept();
if (sendDummyByte) { if (sendDummyByte) {
// send one byte so the client may read() to detect a connection error // send one byte so the client may read() to detect a connection error
@ -76,8 +75,6 @@ public final class DesktopConnection implements Closeable {
throw e; throw e;
} }
} }
} finally {
localServerSocket.close();
} }
} else { } else {
videoSocket = connect(socketName); videoSocket = connect(socketName);