8193302: Javac AssertionError: typeSig ERROR on usage of @Generated
Importing from an invisible package whose name is a prefix of a visible package is not allowed. Reviewed-by: vromero
This commit is contained in:
parent
c2265fb70b
commit
78b7362c97
src
java.compiler/share/classes/javax/annotation/processing
jdk.compiler/share/classes/com/sun/tools/javac
test
jdk
langtools/tools/javac
@ -25,7 +25,6 @@
|
||||
|
||||
package javax.annotation.processing;
|
||||
|
||||
import javax.annotation.*;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.lang.model.element.*;
|
||||
|
||||
|
@ -181,7 +181,8 @@ public enum Source {
|
||||
DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
|
||||
UNDERSCORE_IDENTIFIER(MIN, JDK8),
|
||||
PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
|
||||
LOCAL_VARIABLE_TYPE_INFERENCE(JDK10);
|
||||
LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
|
||||
IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8);
|
||||
|
||||
enum DiagKind {
|
||||
NORMAL,
|
||||
|
@ -3650,17 +3650,8 @@ public class Check {
|
||||
OUTER: for (JCImport imp : toplevel.getImports()) {
|
||||
if (!imp.staticImport && TreeInfo.name(imp.qualid) == names.asterisk) {
|
||||
TypeSymbol tsym = ((JCFieldAccess)imp.qualid).selected.type.tsym;
|
||||
if (toplevel.modle.visiblePackages != null) {
|
||||
//TODO - unclear: selects like javax.* will get resolved from the current module
|
||||
//(as javax is not an exported package from any module). And as javax in the current
|
||||
//module typically does not contain any classes or subpackages, we need to go through
|
||||
//the visible packages to find a sub-package:
|
||||
for (PackageSymbol known : toplevel.modle.visiblePackages.values()) {
|
||||
if (Convert.packagePart(known.fullname) == tsym.flatName())
|
||||
continue OUTER;
|
||||
}
|
||||
}
|
||||
if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
|
||||
if (tsym.kind == PCK && tsym.members().isEmpty() &&
|
||||
!(Feature.IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES.allowedInSource(source) && tsym.exists())) {
|
||||
log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym));
|
||||
}
|
||||
}
|
||||
|
@ -2012,7 +2012,7 @@ public class Resolve {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, sym -> sym.kind == Kind.TYP, false, typeNotFound);
|
||||
}, sym -> sym.kind == Kind.TYP, typeNotFound);
|
||||
}
|
||||
};
|
||||
|
||||
@ -2049,18 +2049,11 @@ public class Resolve {
|
||||
PackageSymbol pack = syms.lookupPackage(env.toplevel.modle, name);
|
||||
|
||||
if (allowModules && isImportOnDemand(env, name)) {
|
||||
pack.complete();
|
||||
if (!pack.exists()) {
|
||||
Name nameAndDot = name.append('.', names.empty);
|
||||
boolean prefixOfKnown =
|
||||
env.toplevel.modle.visiblePackages.values()
|
||||
.stream()
|
||||
.anyMatch(p -> p.fullname.startsWith(nameAndDot));
|
||||
|
||||
if (pack.members().isEmpty()) {
|
||||
return lookupInvisibleSymbol(env, name, syms::getPackagesForName, syms::enterPackage, sym -> {
|
||||
sym.complete();
|
||||
return sym.exists();
|
||||
}, prefixOfKnown, pack);
|
||||
return !sym.members().isEmpty();
|
||||
}, pack);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2087,7 +2080,6 @@ public class Resolve {
|
||||
Function<Name, Iterable<S>> get,
|
||||
BiFunction<ModuleSymbol, Name, S> load,
|
||||
Predicate<S> validate,
|
||||
boolean suppressError,
|
||||
Symbol defaultResult) {
|
||||
//even if a class/package cannot be found in the current module and among packages in modules
|
||||
//it depends on that are exported for any or this module, the class/package may exist internally
|
||||
@ -2097,7 +2089,7 @@ public class Resolve {
|
||||
|
||||
for (S sym : candidates) {
|
||||
if (validate.test(sym))
|
||||
return createInvisibleSymbolError(env, suppressError, sym);
|
||||
return createInvisibleSymbolError(env, sym);
|
||||
}
|
||||
|
||||
Set<ModuleSymbol> recoverableModules = new HashSet<>(syms.getAllModules());
|
||||
@ -2117,7 +2109,7 @@ public class Resolve {
|
||||
S sym = load.apply(ms, name);
|
||||
|
||||
if (sym != null && validate.test(sym)) {
|
||||
return createInvisibleSymbolError(env, suppressError, sym);
|
||||
return createInvisibleSymbolError(env, sym);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2126,11 +2118,11 @@ public class Resolve {
|
||||
return defaultResult;
|
||||
}
|
||||
|
||||
private Symbol createInvisibleSymbolError(Env<AttrContext> env, boolean suppressError, Symbol sym) {
|
||||
private Symbol createInvisibleSymbolError(Env<AttrContext> env, Symbol sym) {
|
||||
if (symbolPackageVisible(env, sym)) {
|
||||
return new AccessError(env, null, sym);
|
||||
} else {
|
||||
return new InvisibleSymbolError(env, suppressError, sym);
|
||||
return new InvisibleSymbolError(env, false, sym);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
import java.rmi.*;
|
||||
import sun.rmi.transport.*;
|
||||
import sun.rmi.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.rmi.dgc.*;
|
||||
|
@ -29,9 +29,7 @@
|
||||
* @run main/othervm JarSigningNonAscii
|
||||
*/
|
||||
|
||||
import sun.security.tools.*;
|
||||
import java.io.*;
|
||||
import java.security.Security;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
import java.security.cert.Certificate;
|
||||
|
@ -23,9 +23,10 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4869999
|
||||
* @bug 4869999 8193302
|
||||
* @summary Verify that the compiler does not prematurely decide a package is not observable.
|
||||
* @compile ImportsObservable.java
|
||||
* @compile -source 8 -Xlint:-options ImportsObservable.java
|
||||
* @compile/fail/ref=ImportsObservable.out -XDrawDiagnostics ImportsObservable.java
|
||||
*/
|
||||
|
||||
import javax.*;
|
||||
|
@ -0,0 +1,2 @@
|
||||
ImportsObservable.java:32:1: compiler.err.doesnt.exist: javax
|
||||
1 error
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8169197 8172668 8173117 8175007 8189765
|
||||
* @bug 8169197 8172668 8173117 8175007 8189765 8193302
|
||||
* @summary Check convenient errors are produced for inaccessible classes.
|
||||
* @library /tools/lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
@ -432,29 +432,6 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase {
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnusedImportOnDemand1(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"package test; import javax.annotation.*; public class Test { }");
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--add-modules", "java.compiler")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run()
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList("");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnusedImportOnDemand2(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
@ -744,4 +721,155 @@ public class ConvenientAccessErrorsTest extends ModuleTestBase {
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackagesUniquelyVisibleInImportOnDemand(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
Path src_ma = src.resolve("ma");
|
||||
tb.writeJavaFiles(src_ma,
|
||||
"module ma { exports ma; }",
|
||||
"package ma; public class Api { }");
|
||||
Path src_mb = src.resolve("mb");
|
||||
tb.writeJavaFiles(src_mb,
|
||||
"module mb { exports ma.mb; }",
|
||||
"package ma.mb; public class Api { }");
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--module-source-path", src.toString())
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
Path test = src.resolve("test");
|
||||
tb.writeJavaFiles(test,
|
||||
"module test { requires mb; }",
|
||||
"package test; import ma.*; public class Test { }");
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--module-path", classes.toString())
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(test))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList(
|
||||
"Test.java:1:22: compiler.err.package.not.visible: ma, (compiler.misc.not.def.access.does.not.read: test, ma, ma)",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackagesUniquelyVisibleInImportOnDemandNoPrefixes(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
Path src_mb = src.resolve("mb");
|
||||
tb.writeJavaFiles(src_mb,
|
||||
"module mb { exports ma.mb; }",
|
||||
"package ma.mb; public class Api { }");
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("--module-source-path", src.toString())
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run()
|
||||
.writeAll();
|
||||
|
||||
Path test = src.resolve("test");
|
||||
tb.writeJavaFiles(test,
|
||||
"module test { requires mb; }",
|
||||
"package test; import ma.mb.*; import ma.*; public class Test { }");
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics",
|
||||
"--module-path", classes.toString())
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(test))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList(
|
||||
"Test.java:1:31: compiler.err.doesnt.exist: ma",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackagesUniquelyVisibleInImportOnDemandThisModule(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
Path test = src.resolve("test");
|
||||
tb.writeJavaFiles(test,
|
||||
"module test { }",
|
||||
"package ma.mb; public class Impl { }",
|
||||
"package test; import ma.*; public class Test { }");
|
||||
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(test))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList(
|
||||
"Test.java:1:15: compiler.err.doesnt.exist: ma",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("-source", "8")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(test.resolve("ma"), test.resolve("test")))
|
||||
.run(Task.Expect.SUCCESS)
|
||||
.writeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackagesUniquelyVisibleInImportOnDemandThisModuleUnnamed(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
Path test = src.resolve("test");
|
||||
tb.writeJavaFiles(test,
|
||||
"package ma.mb; public class Impl { }",
|
||||
"package test; import ma.*; public class Test { }");
|
||||
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(test))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList(
|
||||
"Test.java:1:15: compiler.err.doesnt.exist: ma",
|
||||
"1 error");
|
||||
|
||||
if (!expected.equals(log))
|
||||
throw new Exception("expected output not found; actual: " + log);
|
||||
|
||||
new JavacTask(tb)
|
||||
.options("-source", "8")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(test))
|
||||
.run(Task.Expect.SUCCESS)
|
||||
.writeAll();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user