changeset 49729:cb18edeaeca7

8201443: NoSuchMethodException JarFile.open when jar file is used in classpath Reviewed-by: rriggs, redestad
author sherman
date Thu, 12 Apr 2018 13:30:58 -0700
parents 3852547060c8
children 09905cd87bb2
files src/java.base/share/classes/java/util/zip/ZipFile.java
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/zip/ZipFile.java	Thu Apr 12 19:12:54 2018 +0000
+++ b/src/java.base/share/classes/java/util/zip/ZipFile.java	Thu Apr 12 13:30:58 2018 -0700
@@ -37,7 +37,6 @@
 import java.nio.charset.StandardCharsets;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.nio.file.Files;
-
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -52,13 +51,14 @@
 import java.util.Spliterator;
 import java.util.Spliterators;
 import java.util.WeakHashMap;
-
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.IntFunction;
 import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
+import jdk.internal.misc.JavaLangAccess;
 import jdk.internal.misc.JavaUtilZipFileAccess;
 import jdk.internal.misc.SharedSecrets;
 import jdk.internal.misc.VM;
@@ -834,11 +834,10 @@
         static CleanableResource get(ZipFile zf, File file, int mode)
             throws IOException {
             Class<?> clz = zf.getClass();
-            while (clz != ZipFile.class) {
-                try {
-                    clz.getDeclaredMethod("close");
+            while (clz != ZipFile.class && clz != JarFile.class) {
+                if (JLA.getDeclaredPublicMethods(clz, "close").size() != 0) {
                     return new FinalizableResource(zf, file, mode);
-                } catch (NoSuchMethodException nsme) {}
+                }
                 clz = clz.getSuperclass();
             }
             return new CleanableResource(zf, file, mode);
@@ -1101,6 +1100,8 @@
     }
 
     private static boolean isWindows;
+    private static final JavaLangAccess JLA;
+
     static {
         SharedSecrets.setJavaUtilZipFileAccess(
             new JavaUtilZipFileAccess() {
@@ -1133,6 +1134,7 @@
                 }
              }
         );
+        JLA = jdk.internal.misc.SharedSecrets.getJavaLangAccess();
         isWindows = VM.getSavedProperty("os.name").contains("Windows");
     }