8166675: Latent bug in jar file handling during module path processing.
authorjjg
Thu, 02 Feb 2017 11:40:01 -0800
changeset 43574 042e694725f7
parent 43573 1162c044cf26
child 43575 f202ab5b96b4
8166675: Latent bug in jar file handling during module path processing. Reviewed-by: jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
langtools/test/tools/javac/file/LimitedImage.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Wed Feb 01 20:14:52 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Thu Feb 02 11:40:01 2017 -0800
@@ -43,6 +43,7 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.ProviderNotFoundException;
+import java.nio.file.spi.FileSystemProvider;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -1119,8 +1120,12 @@
                 }
 
                 if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) {
-                    URI uri = URI.create("jar:" + p.toUri());
-                    try (FileSystem fs = FileSystems.newFileSystem(uri, fsEnv, null)) {
+                    FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
+                    if (jarFSProvider == null) {
+                        log.error(Errors.NoZipfsForArchive(p));
+                        return null;
+                    }
+                    try (FileSystem fs = jarFSProvider.newFileSystem(p, fsEnv)) {
                         Path moduleInfoClass = fs.getPath("module-info.class");
                         if (Files.exists(moduleInfoClass)) {
                             String moduleName = readModuleName(moduleInfoClass);
@@ -1132,9 +1137,6 @@
                     } catch (IOException e) {
                         log.error(Errors.LocnCantReadFile(p));
                         return null;
-                    } catch (ProviderNotFoundException e) {
-                        log.error(Errors.NoZipfsForArchive(p));
-                        return null;
                     }
 
                     //automatic module:
@@ -1177,8 +1179,12 @@
                         // workaround for now
                         FileSystem fs = fileSystems.get(p);
                         if (fs == null) {
-                            URI uri = URI.create("jar:" + p.toUri());
-                            fs = FileSystems.newFileSystem(uri, Collections.emptyMap(), null);
+                            FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
+                            if (jarFSProvider == null) {
+                                log.error(Errors.LocnCantReadFile(p));
+                                return null;
+                            }
+                            fs = jarFSProvider.newFileSystem(p, Collections.emptyMap());
                             try {
                                 Path moduleInfoClass = fs.getPath("classes/module-info.class");
                                 String moduleName = readModuleName(moduleInfoClass);
@@ -1194,7 +1200,7 @@
                         }
                     } catch (ModuleNameReader.BadClassFile e) {
                         log.error(Errors.LocnBadModuleInfo(p));
-                    } catch (IOException | ProviderNotFoundException e) {
+                    } catch (IOException e) {
                         log.error(Errors.LocnCantReadFile(p));
                         return null;
                     }
--- a/langtools/test/tools/javac/file/LimitedImage.java	Wed Feb 01 20:14:52 2017 -0800
+++ b/langtools/test/tools/javac/file/LimitedImage.java	Thu Feb 02 11:40:01 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -74,6 +74,7 @@
         );
 
         //check proper diagnostics when zip/jar FS not present:
+        System.err.println("Test " + testJar + " on classpath");
         actualOutput = new JavacTask(tb, Mode.CMDLINE)
                 .classpath(testJar)
                 .options("-XDrawDiagnostics")
@@ -84,9 +85,10 @@
                 .getOutputLines(OutputKind.DIRECT);
 
         if (!expectedOutput.equals(actualOutput)) {
-            throw new AssertionError("Unexpected output: " + actualOutput);
+            throw new AssertionError("Unexpected output");
         }
 
+        System.err.println("Test " + testJar + " on sourcepath");
         actualOutput = new JavacTask(tb, Mode.CMDLINE)
                 .sourcepath(testJar)
                 .options("-XDrawDiagnostics")
@@ -97,9 +99,10 @@
                 .getOutputLines(OutputKind.DIRECT);
 
         if (!expectedOutput.equals(actualOutput)) {
-            throw new AssertionError("Unexpected output: " + actualOutput);
+            throw new AssertionError("Unexpected output");
         }
 
+        System.err.println("Test " + testJar + " on modulepath");
         actualOutput = new JavacTask(tb, Mode.CMDLINE)
                 .options("-XDrawDiagnostics",
                          "--module-path", testJar.toString())
@@ -110,7 +113,7 @@
                 .getOutputLines(OutputKind.DIRECT);
 
         if (!expectedOutput.equals(actualOutput)) {
-            throw new AssertionError("Unexpected output: " + actualOutput);
+            throw new AssertionError("Unexpected output");
         }
 
         expectedOutput = Arrays.asList(
@@ -118,6 +121,7 @@
                 "1 error"
         );
 
+        System.err.println("Test directory containing " + testJar + " on modulepath");
         actualOutput = new JavacTask(tb, Mode.CMDLINE)
                 .classpath()
                 .options("-XDrawDiagnostics",
@@ -129,7 +133,7 @@
                 .getOutputLines(OutputKind.DIRECT);
 
         if (!expectedOutput.equals(actualOutput)) {
-            throw new AssertionError("Unexpected output: " + actualOutput);
+            throw new AssertionError("Unexpected output");
         }
     }