Use try-with-resources instead of try-finally
This commit is contained in:
parent
a17d66463d
commit
f5cd0ec302
|
@ -99,17 +99,8 @@ public class LdapServerBeanDefinitionParserTests {
|
|||
}
|
||||
|
||||
private int getDefaultPort() throws IOException {
|
||||
ServerSocket server = null;
|
||||
try {
|
||||
server = new ServerSocket(0);
|
||||
try (ServerSocket server = new ServerSocket(0)) {
|
||||
return server.getLocalPort();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
server.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,21 +38,13 @@ public class JavaVersionTests {
|
|||
|
||||
private void assertClassVersion(Class<?> clazz) throws Exception {
|
||||
String classResourceName = clazz.getName().replaceAll("\\.", "/") + ".class";
|
||||
InputStream input = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream(classResourceName);
|
||||
try {
|
||||
try (InputStream input = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream(classResourceName)) {
|
||||
DataInputStream data = new DataInputStream(input);
|
||||
data.readInt();
|
||||
data.readShort(); // minor
|
||||
int major = data.readShort();
|
||||
assertThat(major).isEqualTo(JDK8_CLASS_VERSION);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
input.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue