mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-13 04:27:53 +00:00
8387865: ThisEscapeAnalyzer crashes for erroneous source code
Reviewed-by: asotona, vromero
This commit is contained in:
parent
5926bbfa0a
commit
ff32e76f48
@ -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
|
||||
|
||||
@ -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<String> 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<String> 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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user