8322159: ThisEscapeAnalyzer crashes for erroneous code
Reviewed-by: vromero
This commit is contained in:
parent
d4fb30885b
commit
7455b1b527
@ -506,7 +506,7 @@ class ThisEscapeAnalyzer extends TreeScanner {
|
||||
public void visitApply(JCMethodInvocation invoke) {
|
||||
|
||||
// Get method symbol
|
||||
MethodSymbol sym = (MethodSymbol)TreeInfo.symbolFor(invoke.meth);
|
||||
Symbol sym = TreeInfo.symbolFor(invoke.meth);
|
||||
|
||||
// Recurse on method expression
|
||||
scan(invoke.meth);
|
||||
@ -530,7 +530,7 @@ class ThisEscapeAnalyzer extends TreeScanner {
|
||||
invoke(invoke, sym, invoke.args, receiverRefs);
|
||||
}
|
||||
|
||||
private void invoke(JCTree site, MethodSymbol sym, List<JCExpression> args, RefSet<?> receiverRefs) {
|
||||
private void invoke(JCTree site, Symbol sym, List<JCExpression> args, RefSet<?> receiverRefs) {
|
||||
|
||||
// Skip if ignoring warnings for a constructor invoked via 'this()'
|
||||
if (suppressed.contains(sym))
|
||||
@ -810,6 +810,10 @@ class ThisEscapeAnalyzer extends TreeScanner {
|
||||
|
||||
@Override
|
||||
public void visitReference(JCMemberReference tree) {
|
||||
if (tree.type.isErroneous()) {
|
||||
//error recovery - ignore erroneous member references
|
||||
return ;
|
||||
}
|
||||
|
||||
// Scan target expression and extract 'this' references, if any
|
||||
scan(tree.expr);
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8301580
|
||||
* @bug 8301580 8322159
|
||||
* @summary Verify error recovery w.r.t. Attr
|
||||
* @library /tools/lib
|
||||
* @enablePreview
|
||||
@ -87,4 +87,41 @@ public class AttrRecovery extends TestRunner {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testX() throws Exception {
|
||||
String code = """
|
||||
public class C {
|
||||
public C() {
|
||||
Undefined.method();
|
||||
undefined1();
|
||||
Runnable r = this::undefined2;
|
||||
overridable(this); //to verify ThisEscapeAnalyzer has been run
|
||||
}
|
||||
public void overridable(C c) {}
|
||||
}
|
||||
""";
|
||||
Path curPath = Path.of(".");
|
||||
List<String> actual = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics", "-XDdev",
|
||||
"-XDshould-stop.at=FLOW", "-Xlint:this-escape")
|
||||
.sources(code)
|
||||
.outdir(curPath)
|
||||
.run(Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = List.of(
|
||||
"C.java:3:9: compiler.err.cant.resolve.location: kindname.variable, Undefined, , , (compiler.misc.location: kindname.class, C, null)",
|
||||
"C.java:4:9: compiler.err.cant.resolve.location.args: kindname.method, undefined1, , , (compiler.misc.location: kindname.class, C, null)",
|
||||
"C.java:5:22: compiler.err.invalid.mref: kindname.method, (compiler.misc.cant.resolve.location.args: kindname.method, undefined2, , , (compiler.misc.location: kindname.class, C, null))",
|
||||
"C.java:6:20: compiler.warn.possible.this.escape",
|
||||
"3 errors",
|
||||
"1 warning"
|
||||
);
|
||||
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
error("Expected: " + expected + ", but got: " + actual);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user