changeset 3940:dc59890c8a7e

8166675: Latent bug in jar file handling during module path processing. Reviewed-by: jlahoda
author jjg
date Thu, 02 Feb 2017 11:40:01 -0800
parents 1fee6f0b43ba
children b281bea7ebe9
files src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java test/tools/javac/file/LimitedImage.java
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Wed Feb 01 20:14:52 2017 -0800
+++ b/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/test/tools/javac/file/LimitedImage.java	Wed Feb 01 20:14:52 2017 -0800
+++ b/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");
         }
     }