8167630: jdeps --generate-module-info forgets to close the resource after checking any unnamed package
authormchung
Wed, 12 Oct 2016 17:27:54 -0700
changeset 41522 2fb1e2da56ca
parent 41521 9f45ffccd1c8
child 41523 da4f500b886d
8167630: jdeps --generate-module-info forgets to close the resource after checking any unnamed package Reviewed-by: lancea, ksrini
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Wed Oct 12 15:37:27 2016 -0700
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Wed Oct 12 17:27:54 2016 -0700
@@ -680,20 +680,21 @@
     private boolean genModuleInfo(JdepsConfiguration config) throws IOException {
         // check if any JAR file contains unnamed package
         for (String arg : inputArgs) {
-            Optional<String> classInUnnamedPackage =
-                ClassFileReader.newInstance(Paths.get(arg))
-                    .entries().stream()
-                    .filter(n -> n.endsWith(".class"))
-                    .filter(cn -> toPackageName(cn).isEmpty())
-                    .findFirst();
+            try (ClassFileReader reader = ClassFileReader.newInstance(Paths.get(arg))) {
+                Optional<String> classInUnnamedPackage =
+                    reader.entries().stream()
+                        .filter(n -> n.endsWith(".class"))
+                        .filter(cn -> toPackageName(cn).isEmpty())
+                        .findFirst();
 
-            if (classInUnnamedPackage.isPresent()) {
-                if (classInUnnamedPackage.get().equals("module-info.class")) {
-                    reportError("err.genmoduleinfo.not.jarfile", arg);
-                } else {
-                    reportError("err.genmoduleinfo.unnamed.package", arg);
+                if (classInUnnamedPackage.isPresent()) {
+                    if (classInUnnamedPackage.get().equals("module-info.class")) {
+                        reportError("err.genmoduleinfo.not.jarfile", arg);
+                    } else {
+                        reportError("err.genmoduleinfo.unnamed.package", arg);
+                    }
+                    return false;
                 }
-                return false;
             }
         }