From b22810b17c1319f02919af493aa174db5d2e174e Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 27 Jan 2023 21:59:26 +0100 Subject: [PATCH] Use try-with-resources Replace an explicit try-finally by a try-with-resources block. --- .../main/java/com/genymobile/scrcpy/DesktopConnection.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java index 54a40d22..7f287a6a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java +++ b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java @@ -61,8 +61,7 @@ public final class DesktopConnection implements Closeable { LocalSocket videoSocket; LocalSocket controlSocket = null; if (tunnelForward) { - LocalServerSocket localServerSocket = new LocalServerSocket(socketName); - try { + try (LocalServerSocket localServerSocket = new LocalServerSocket(socketName)) { videoSocket = localServerSocket.accept(); if (sendDummyByte) { // 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; } } - } finally { - localServerSocket.close(); } } else { videoSocket = connect(socketName);