changeset 3359:2aa0433e0add

8154283: Check for clash between package and class not working when package in a different module Summary: Looking for any visible package when checking for package-class clash Reviewed-by: jjg
author jlahoda
date Fri, 15 Apr 2016 11:39:31 +0200
parents 3e3553ee39d9
children 8102be8ddff2
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java test/tools/javac/modules/EdgeCases.java
diffstat 3 files changed, 37 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Mon Apr 25 08:50:16 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Fri Apr 15 11:39:31 2016 +0200
@@ -698,7 +698,7 @@
      */
     public boolean packageExists(ModuleSymbol msym, Name fullname) {
         Assert.checkNonNull(msym);
-        return enterPackage(msym, fullname).exists();
+        return lookupPackage(msym, fullname).exists();
     }
 
     /** Make a package, given its fully qualified name.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Mon Apr 25 08:50:16 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Apr 15 11:39:31 2016 +0200
@@ -53,10 +53,6 @@
 public class MemberEnter extends JCTree.Visitor {
     protected static final Context.Key<MemberEnter> memberEnterKey = new Context.Key<>();
 
-    /** A switch to determine whether we check for package/class conflicts
-     */
-    final static boolean checkClash = true;
-
     private final Enter enter;
     private final Log log;
     private final Check chk;
--- a/test/tools/javac/modules/EdgeCases.java	Mon Apr 25 08:50:16 2016 -0700
+++ b/test/tools/javac/modules/EdgeCases.java	Fri Apr 15 11:39:31 2016 +0200
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8154283
  * @summary tests for multi-module mode compilation
  * @library /tools/lib
  * @modules
@@ -57,7 +58,6 @@
 import toolbox.JarTask;
 import toolbox.JavacTask;
 import toolbox.Task;
-import toolbox.ToolBox;
 
 public class EdgeCases extends ModuleTestBase {
 
@@ -269,4 +269,39 @@
 
     }
 
+    @Test
+    void testClassPackageClash(Path base) throws Exception {
+        Path src = base.resolve("src");
+        Path src_m1 = src.resolve("m1");
+        tb.writeJavaFiles(src_m1,
+                          "module m1 { exports test.m1; }",
+                          "package test.m1;\n" +
+                          "public class Test {}\n");
+        Path src_m2 = src.resolve("m2");
+        tb.writeJavaFiles(src_m2,
+                          "module m2 { requires m1; }",
+                          "package test;\n" +
+                          "public class m1 {}\n");
+        Path classes = base.resolve("classes");
+        tb.createDirectories(classes);
+
+        List<String> log = new JavacTask(tb)
+                .options("-modulesourcepath", src.toString(),
+                         "-XDrawDiagnostics")
+                .outdir(classes)
+                .files(findJavaFiles(src))
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutputLines(Task.OutputKind.DIRECT);
+
+        List<String> expected = Arrays.asList(
+            "m1.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1",
+            "1 error"
+        );
+
+        if (!expected.equals(log)) {
+            throw new IllegalStateException(log.toString());
+        }
+    }
+
 }