]> source.dussan.org Git - aspectj.git/commitdiff
AjBuildManager: use try with resources in 2 places
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Thu, 11 Mar 2021 06:16:46 +0000 (13:16 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Thu, 11 Mar 2021 06:16:46 +0000 (13:16 +0700)
I was debugging something in ModuleTests, trying to find out if there
are resource leaks. They were not in this class but in FileUtil - see
next commit. However, the little refactoring here does not hurt either.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java

index fb086e9f3f552bd1774537e13ec3f06783382331..87df28f0c802fcc69dee1563226e64f295c598e5 100644 (file)
@@ -476,9 +476,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
        }
 
        private void copyResourcesFromJarFile(File jarFile) throws IOException {
-               JarInputStream inStream = null;
-               try {
-                       inStream = new JarInputStream(new FileInputStream(jarFile));
+               try (JarInputStream inStream = new JarInputStream(new FileInputStream(jarFile))) {
                        while (true) {
                                ZipEntry entry = inStream.getNextEntry();
                                if (entry == null) {
@@ -496,10 +494,6 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
 
                                inStream.closeEntry();
                        }
-               } finally {
-                       if (inStream != null) {
-                               inStream.close();
-                       }
                }
        }