8154283: Check for clash between package and class not working when package in a different module

Looking for any visible package when checking for package-class clash

Reviewed-by: jjg
This commit is contained in:
Jan Lahoda 2016-04-15 11:39:31 +02:00
parent 0a3a2c3ebe
commit d20efa360f
3 changed files with 37 additions and 6 deletions

View file

@ -698,7 +698,7 @@ public class Symtab {
*/
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.

View file

@ -53,10 +53,6 @@ import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
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;

View file

@ -23,6 +23,7 @@
/*
* @test
* @bug 8154283
* @summary tests for multi-module mode compilation
* @library /tools/lib
* @modules
@ -57,7 +58,6 @@ import com.sun.tools.javac.code.Symbol.ModuleSymbol;
import toolbox.JarTask;
import toolbox.JavacTask;
import toolbox.Task;
import toolbox.ToolBox;
public class EdgeCases extends ModuleTestBase {
@ -269,4 +269,39 @@ public class EdgeCases extends ModuleTestBase {
}
@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());
}
}
}