8189765: Improve error reporting for compiling against package not visible due to modules
authorjlahoda
Thu, 12 Apr 2018 09:23:34 +0200
changeset 49579 fce4252d5227
parent 49578 0c3e252cea44
child 49580 62b908c9f0e6
child 56421 92bea2b7732a
8189765: Improve error reporting for compiling against package not visible due to modules Summary: When looking in other modules for an undefined Symbol, also look into the unnamed module. Reviewed-by: mcimadamore
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
test/langtools/tools/javac/modules/CompileModulePatchTest.java
test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java
test/langtools/tools/javac/modules/ModulesAndClassPathTest.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Apr 12 10:19:31 2018 +0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Apr 12 09:23:34 2018 +0200
@@ -2120,6 +2120,7 @@
 
         Set<ModuleSymbol> recoverableModules = new HashSet<>(syms.getAllModules());
 
+        recoverableModules.add(syms.unnamedModule);
         recoverableModules.remove(env.toplevel.modle);
 
         for (ModuleSymbol ms : recoverableModules) {
--- a/test/langtools/tools/javac/modules/CompileModulePatchTest.java	Thu Apr 12 10:19:31 2018 +0800
+++ b/test/langtools/tools/javac/modules/CompileModulePatchTest.java	Thu Apr 12 09:23:34 2018 +0200
@@ -252,7 +252,7 @@
                 .getOutputLines(Task.OutputKind.DIRECT);
 
         List<String> expectedOut = Arrays.asList(
-                "Extra.java:1:76: compiler.err.doesnt.exist: p",
+                "Extra.java:1:75: compiler.err.package.not.visible: p, (compiler.misc.not.def.access.does.not.read.unnamed: p, java.compiler)",
                 "1 error"
         );
 
--- a/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java	Thu Apr 12 10:19:31 2018 +0800
+++ b/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java	Thu Apr 12 09:23:34 2018 +0200
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8169197 8172668 8173117 8175007
+ * @bug 8169197 8172668 8173117 8175007 8189765
  * @summary Check convenient errors are produced for inaccessible classes.
  * @library /tools/lib
  * @modules jdk.compiler/com.sun.tools.javac.api
@@ -199,7 +199,7 @@
             throw new Exception("expected output not found; actual: " + log);
     }
 
-//    @Test
+    @Test
     public void testInaccessibleUnnamedModule(Path base) throws Exception {
         Path jar = prepareTestJar(base, "package api; class Api { public static class Foo {} }");
 
@@ -224,8 +224,8 @@
                 .getOutputLines(Task.OutputKind.DIRECT);
 
         List<String> expected = Arrays.asList(
-                "Test.java:1:38: compiler.err.not.def.access.package.cant.access: api.Api, api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m1x)",
-                "Test.java:1:51: compiler.err.not.def.access.package.cant.access: api.Api, api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m1x)",
+                "Test.java:1:35: compiler.err.package.not.visible: api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m1x)",
+                "Test.java:1:48: compiler.err.package.not.visible: api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m1x)",
                 "2 errors");
 
         if (!expected.equals(log))
--- a/test/langtools/tools/javac/modules/ModulesAndClassPathTest.java	Thu Apr 12 10:19:31 2018 +0800
+++ b/test/langtools/tools/javac/modules/ModulesAndClassPathTest.java	Thu Apr 12 09:23:34 2018 +0200
@@ -77,7 +77,7 @@
                                 .writeAll()
                                 .getOutputLines(Task.OutputKind.DIRECT);
 
-        List<String> expected = Arrays.asList("Impl.java:1:38: compiler.err.doesnt.exist: api",
+        List<String> expected = Arrays.asList("Impl.java:1:35: compiler.err.package.not.visible: api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m)",
                                               "1 error");
 
         if (!expected.equals(modLog)) {
@@ -129,7 +129,7 @@
                                 .writeAll()
                                 .getOutputLines(Task.OutputKind.DIRECT);
 
-        List<String> expected = Arrays.asList("Impl.java:1:38: compiler.err.doesnt.exist: api",
+        List<String> expected = Arrays.asList("Impl.java:1:35: compiler.err.package.not.visible: api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m)",
                                               "1 error");
 
         if (!expected.equals(modLog)) {
@@ -170,7 +170,7 @@
                                 .writeAll()
                                 .getOutputLines(Task.OutputKind.DIRECT);
 
-        List<String> expected = Arrays.asList("Impl.java:1:38: compiler.err.doesnt.exist: api",
+        List<String> expected = Arrays.asList("Impl.java:1:35: compiler.err.package.not.visible: api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m)",
                                               "1 error");
 
         if (!expected.equals(modLog)) {