Use try-with-resources statements

See gh-26449
This commit is contained in:
weixsun
2021-05-13 17:06:49 +08:00
committed by Andy Wilkinson
parent 32d378a348
commit 5ba9db391f
2 changed files with 6 additions and 22 deletions

View File

@@ -172,13 +172,9 @@ class HandlerTests {
TestJarCreator.createTestJar(testJar);
URL url = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/3.dat", this.handler);
JarURLConnection connection = (JarURLConnection) url.openConnection();
JarFile jarFile = JarFileWrapper.unwrap(connection.getJarFile());
try {
try (JarFile jarFile = JarFileWrapper.unwrap(connection.getJarFile())) {
assertThat(jarFile.getRootJarFile().getFile()).isEqualTo(testJar);
}
finally {
jarFile.close();
}
}
@Test
@@ -187,13 +183,9 @@ class HandlerTests {
TestJarCreator.createTestJar(testJar);
URL url = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/3.dat", this.handler);
JarURLConnection connection = (JarURLConnection) url.openConnection();
JarFile jarFile = JarFileWrapper.unwrap(connection.getJarFile());
try {
try (JarFile jarFile = JarFileWrapper.unwrap(connection.getJarFile())) {
assertThat(jarFile.getRootJarFile().getFile()).isEqualTo(testJar);
}
finally {
jarFile.close();
}
}
private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec) throws MalformedURLException {