changeset 3702:2fd02a123cf0

8167630: jdeps --generate-module-info forgets to close the resource after checking any unnamed package Reviewed-by: lancea, ksrini
author mchung
date Wed, 12 Oct 2016 17:27:54 -0700
parents de2329607ab5
children 673c53147055
files src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Wed Oct 12 15:37:27 2016 -0700
+++ b/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;
             }
         }