8264258: Unknown lookups in the java package give misleading compilation errors
Reviewed-by: sadayapalam
This commit is contained in:
parent
a9367dbd84
commit
83364a4b4a
@ -4061,7 +4061,7 @@ public class Resolve {
|
||||
location = site.tsym;
|
||||
}
|
||||
if (!location.name.isEmpty()) {
|
||||
if (location.kind == PCK && !site.tsym.exists()) {
|
||||
if (location.kind == PCK && !site.tsym.exists() && location.name != names.java) {
|
||||
return diags.create(dkind, log.currentSource(), pos,
|
||||
"doesnt.exist", location);
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ public class Names {
|
||||
public final Name Method;
|
||||
|
||||
// package names
|
||||
public final Name java;
|
||||
public final Name java_lang;
|
||||
|
||||
// module names
|
||||
@ -291,6 +292,7 @@ public class Names {
|
||||
Method = fromString("Method");
|
||||
|
||||
// package names
|
||||
java = fromString("java");
|
||||
java_lang = fromString("java.lang");
|
||||
|
||||
// module names
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8264258
|
||||
* @summary Unknown lookups in the java package give misleading compilation errors
|
||||
* @compile/fail/ref=MisleadingNonExistentPathError.out -XDrawDiagnostics MisleadingNonExistentPathError.java
|
||||
*/
|
||||
package knownpkg;
|
||||
|
||||
public class MisleadingNonExistentPathError {
|
||||
|
||||
void classNotFound() {
|
||||
// Not found, but in an existing package
|
||||
Class<?> c1 = knownpkg.NotFound.class;
|
||||
|
||||
// Not found, but in a (system) package which exists and is in scope
|
||||
Class<?> c2 = java.lang.NotFound.class;
|
||||
|
||||
// Not found, on a genuinely unknown package
|
||||
Class<?> c3 = unknownpkg.NotFound.class;
|
||||
|
||||
// Not found, but in the 'java' package which is in scope as per JLS 6.3 and observable as per JLS 7.4.3
|
||||
Class<?> c4 = java.NotFound.class;
|
||||
|
||||
// Not found, but in a (system) package which exists and is in scope
|
||||
Object c5 = new java.lang();
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
MisleadingNonExistentPathError.java:13:31: compiler.err.cant.resolve.location: kindname.class, NotFound, , , (compiler.misc.location: kindname.package, knownpkg, null)
|
||||
MisleadingNonExistentPathError.java:16:32: compiler.err.cant.resolve.location: kindname.class, NotFound, , , (compiler.misc.location: kindname.package, java.lang, null)
|
||||
MisleadingNonExistentPathError.java:19:33: compiler.err.doesnt.exist: unknownpkg
|
||||
MisleadingNonExistentPathError.java:22:27: compiler.err.cant.resolve.location: kindname.class, NotFound, , , (compiler.misc.location: kindname.package, java, null)
|
||||
MisleadingNonExistentPathError.java:25:29: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null)
|
||||
5 errors
|
@ -1,5 +1,5 @@
|
||||
TwrForVariable3.java:15:14: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.AutoCloseable))
|
||||
TwrForVariable3.java:18:14: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.AutoCloseable))
|
||||
TwrForVariable3.java:21:18: compiler.err.doesnt.exist: java
|
||||
TwrForVariable3.java:21:18: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null)
|
||||
TwrForVariable3.java:24:14: compiler.err.cant.resolve.location: kindname.variable, java, , , (compiler.misc.location: kindname.class, TwrForVariable3, null)
|
||||
4 errors
|
||||
|
Loading…
Reference in New Issue
Block a user