Use try-with-resources instead of try-finally

This commit is contained in:
Lars Grefer
2019-08-06 00:50:47 +02:00
committed by Rob Winch
parent a17d66463d
commit f5cd0ec302
3 changed files with 4 additions and 32 deletions

View File

@@ -114,19 +114,8 @@ public final class ApacheDSServerIntegrationTests {
*/
private static int getAvailablePort() throws IOException {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(0);
try (ServerSocket serverSocket = new ServerSocket(0)) {
return serverSocket.getLocalPort();
}
finally {
if (serverSocket != null) {
try {
serverSocket.close();
}
catch (IOException e) {
}
}
}
}
}