diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index 6fb1feed08d..e24b331dd63 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -873,11 +873,10 @@ public class ThisEscapeAnalyzer extends TreeScanner { @Override public void visitAssign(JCAssign tree) { - VarSymbol sym = (VarSymbol)TreeInfo.symbolFor(tree.lhs); scan(tree.lhs); refs.discardExprs(depth); scan(tree.rhs); - if (isParamOrVar(sym)) + if (TreeInfo.symbolFor(tree.lhs) instanceof VarSymbol sym && isParamOrVar(sym)) refs.replaceExprs(depth, ref -> new VarRef(sym, ref)); else refs.discardExprs(depth); // we don't track fields yet diff --git a/test/langtools/tools/javac/recovery/AttrRecovery.java b/test/langtools/tools/javac/recovery/AttrRecovery.java index 64aaad2a184..fb852b5b3f2 100644 --- a/test/langtools/tools/javac/recovery/AttrRecovery.java +++ b/test/langtools/tools/javac/recovery/AttrRecovery.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8301580 8322159 8333107 8332230 8338678 8351260 8366196 8372336 8373094 8384229 + * @bug 8301580 8322159 8333107 8332230 8338678 8351260 8366196 8372336 8373094 8384229 8387865 * @summary Verify error recovery w.r.t. Attr * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api @@ -860,6 +860,33 @@ public class AttrRecovery { .writeAll(); } + @Test //JDK-8387865 + public void testThisEscapeUnknownField() throws Exception { + String code = """ + public class C { + public C() { + this.unknown = unknown; + } + } + """; + List actual = new JavacTask(tb) + .options("-XDrawDiagnostics", "-XDdev", + "-XDshould-stop.at=WARN", "-Xlint:this-escape") + .sources(code) + .outdir(base) + .run(Expect.FAIL) + .writeAll() + .getOutputLines(OutputKind.DIRECT); + + List expected = List.of( + "C.java:3:13: compiler.err.cant.resolve: kindname.variable, unknown, , ", + "C.java:3:24: compiler.err.cant.resolve.location: kindname.variable, unknown, , , (compiler.misc.location: kindname.class, C, null)", + "2 errors" + ); + + assertEquals(expected, actual); + } + @BeforeEach public void setUp(TestInfo info) throws IOException { base = Path.of(info.getTestMethod().orElseThrow().getName());