Skip to content

Commit e50c413

Browse files
committed
8384229: Previously accepted code is rejected after JDK-8378102
Reviewed-by: vromero
1 parent 1161970 commit e50c413

2 files changed

Lines changed: 66 additions & 5 deletions

File tree

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,8 +2358,9 @@ Symbol findGlobalType(Env<AttrContext> env, Scope scope, Name name, RecoveryLoad
23582358
bestSoFar != sym) {
23592359
return new AmbiguityError(bestSoFar, sym);
23602360
} else if (env.toplevel.namedImportScope == scope &&
2361-
(sym == typeNotFound || (sym.kind == ERR && s.kind == ERR))) {
2362-
bestSoFar = bestOf(bestSoFar, new UnresolvableGobalSymbolError(s));
2361+
((sym == typeNotFound && s.kind.matches(KindSelector.TYP)) ||
2362+
(sym.kind == ERR && s.kind == ERR))) {
2363+
bestSoFar = bestOf(bestSoFar, new UnresolvableGlobalSymbolError(s));
23632364
} else
23642365
bestSoFar = bestOf(bestSoFar, sym);
23652366
}
@@ -4157,9 +4158,9 @@ abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
41574158
List<Type> typeargtypes);
41584159
}
41594160

4160-
class UnresolvableGobalSymbolError extends InvalidSymbolError {
4161+
class UnresolvableGlobalSymbolError extends InvalidSymbolError {
41614162

4162-
UnresolvableGobalSymbolError(Symbol sym) {
4163+
UnresolvableGlobalSymbolError(Symbol sym) {
41634164
super(HIDDEN, sym, "unresolvable class error");
41644165
this.name = sym.name;
41654166
}

test/langtools/tools/javac/recovery/AttrRecovery.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8301580 8322159 8333107 8332230 8338678 8351260 8366196 8372336 8373094
26+
* @bug 8301580 8322159 8333107 8332230 8338678 8351260 8366196 8372336 8373094 8384229
2727
* @summary Verify error recovery w.r.t. Attr
2828
* @library /tools/lib
2929
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -800,6 +800,66 @@ public Void visitVariable(VariableTree tree, Void p) {
800800
assertEquals(expected, actual);
801801
}
802802

803+
@Test //JDK-8384229
804+
public void testStaticFieldTypeLookup() throws Exception {
805+
Path out = base.resolve("out");
806+
807+
Files.createDirectories(out);
808+
809+
new JavacTask(tb)
810+
.options("-XDrawDiagnostics",
811+
"-XDdev")
812+
.sources("""
813+
package test;
814+
import static test.A.Object;
815+
enum A {
816+
Object;
817+
}
818+
class Test {
819+
void foo() {
820+
Object f = "";
821+
}
822+
}
823+
""")
824+
.outdir(out)
825+
.run()
826+
.writeAll();
827+
828+
new JavacTask(tb)
829+
.options("-XDrawDiagnostics",
830+
"-XDdev")
831+
.sources("""
832+
package test;
833+
import static test.A.Object;
834+
enum A {
835+
Object;
836+
}
837+
class Test {
838+
private static final Object f = "";
839+
}
840+
""")
841+
.outdir(out)
842+
.run()
843+
.writeAll();
844+
845+
new JavacTask(tb)
846+
.options("-XDrawDiagnostics",
847+
"-XDdev")
848+
.sources("""
849+
package test;
850+
import static test.A.Object;
851+
class A {
852+
public static java.lang.Object Object() { return null; }
853+
}
854+
class Test {
855+
private static final Object f = Object();
856+
}
857+
""")
858+
.outdir(out)
859+
.run()
860+
.writeAll();
861+
}
862+
803863
@BeforeEach
804864
public void setUp(TestInfo info) throws IOException {
805865
base = Path.of(info.getTestMethod().orElseThrow().getName());

0 commit comments

Comments
 (0)