8249829: javac is issuing an incorrect static access error

Reviewed-by: jlahoda
This commit is contained in:
Vicente Romero 2020-07-27 10:12:30 -04:00
parent af8c3b4a7e
commit 6c2ff1781b
2 changed files with 46 additions and 6 deletions

View File

@ -2289,13 +2289,11 @@ public class Resolve {
}
boolean isInnerClassOfMethod(Symbol msym, Symbol csym) {
if (csym.owner == msym && !csym.isStatic()) {
return true;
} else if (csym.owner.kind == TYP) {
return isInnerClassOfMethod(msym, csym.owner);
} else {
return false;
while (csym.owner != msym) {
if (csym.isStatic()) return false;
csym = csym.owner.enclClass();
}
return (csym.owner == msym && !csym.isStatic());
}
/** Find an unqualified type symbol.

View File

@ -800,6 +800,48 @@ public class RecordCompilationTests extends CompilationTestCase {
}
"""
);
// positive cases
assertOK(
"""
import java.security.*;
class Test {
static Test newInstance(Object provider) {
return new Test() {
private final PrivilegedExceptionAction<KeyStore> action = new PrivilegedExceptionAction<KeyStore>() {
public KeyStore run() throws Exception {
if (provider == null) {}
return null;
}
};
};
}
}
"""
);
assertOK(
"""
import java.security.*;
class Test {
static Test newInstance(Object provider) {
return new Test() {
int m(PrivilegedExceptionAction<KeyStore> a) { return 0; }
{
m(
new PrivilegedExceptionAction<KeyStore>() {
public KeyStore run() throws Exception {
if (provider == null) {}
return null;
}
}
);
}
};
}
}
"""
);
}
public void testReturnInCanonical_Compact() {