Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8263432: javac may report an invalid package/class clash on case insensitive filesystems #184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, 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
@@ -648,6 +648,10 @@ public ClassSymbol getClass(ModuleSymbol msym, Name flatName) {
}

public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) {
return lookupPackage(msym, flatName, false);
}

private PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName, boolean onlyExisting) {
Assert.checkNonNull(msym);

if (flatName.isEmpty()) {
@@ -670,7 +674,7 @@ public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) {

pack = getPackage(msym, flatName);

if (pack != null && pack.exists())
if ((pack != null && pack.exists()) || onlyExisting)
return pack;

boolean dependsOnUnnamed = msym.requires != null &&
@@ -742,7 +746,8 @@ public ClassSymbol enterClass(ModuleSymbol msym, Name flatname) {
*/
public boolean packageExists(ModuleSymbol msym, Name fullname) {
Assert.checkNonNull(msym);
return lookupPackage(msym, fullname).exists();
PackageSymbol pack = lookupPackage(msym, fullname, true);
return pack != null && pack.exists();
}

/** Make a package, given its fully qualified name.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -23,7 +23,7 @@

/**
* @test
* @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747
* @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747 8263432
* @summary Verify that annotation processing works.
* @library /tools/lib
* @modules
@@ -44,6 +44,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -78,6 +79,7 @@
import javax.lang.model.util.ElementScanner9;
import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileManager;
@@ -1551,6 +1553,101 @@ public void testWrongDefaultTargetModule(Path base) throws Exception {
}
}

@Test
public void testClassPhantomPackageClash(Path base) throws Exception {
Path classes = base.resolve("classes");

Files.createDirectories(classes);

Path src = base.resolve("src");

tb.writeJavaFiles(src,
"module m {}",
"package api; public class Nested {}",
"package api.nested; public class C {}");

class TestFileManager extends ForwardingJavaFileManager<JavaFileManager>
implements StandardJavaFileManager {

public TestFileManager(StandardJavaFileManager fileManager) {
super(fileManager);
}

@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
if ("api.Nested".equals(packageName)) {
//simulate case insensitive filesystem:
packageName = "api.nested";
}
return super.list(location, packageName, kinds, recurse);
}

@Override
public void setLocationFromPaths(Location location, Collection<? extends Path> paths) throws IOException {
((StandardJavaFileManager) fileManager).setLocationFromPaths(location, paths);
}

@Override
public Iterable<? extends Path> getLocationAsPaths(Location location) {
return ((StandardJavaFileManager) fileManager).getLocationAsPaths(location);
}

@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
throw new UnsupportedOperationException();
}

@Override
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
throw new UnsupportedOperationException();
}

@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
throw new UnsupportedOperationException();
}

@Override
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
throw new UnsupportedOperationException();
}

@Override
public void setLocation(Location location, Iterable<? extends File> files) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public Iterable<? extends File> getLocation(Location location) {
throw new UnsupportedOperationException();
}
}

try (StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
JavaFileManager testFM = new TestFileManager(fm)) {
new JavacTask(tb)
.fileManager(testFM)
.options("-processor", NoOpTestAP.class.getName(),
"-sourcepath", src.toString())
.outdir(classes)
.files(src.resolve("module-info.java"),
src.resolve("api").resolve("Nested.java"))
.run()
.writeAll()
.getOutputLines(OutputKind.STDERR);
}
}

@SupportedAnnotationTypes("*")
public static final class NoOpTestAP extends AbstractProcessor {

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}

}

private static void assertNonNull(String msg, Object val) {
if (val == null) {
throw new AssertionError(msg);