8062747: Compiler error when anonymous class uses method with parametrized exception

When inferring lambda's thrown types, avoid tracking variables that are not under the lambda to avoid crashes.

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2014-11-14 11:58:28 +01:00
parent 99895e4249
commit e158f32141
2 changed files with 31 additions and 1 deletions

View File

@ -242,9 +242,15 @@ public class Flow {
Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
try {
new AssignAnalyzer() {
WriteableScope enclosedSymbols = WriteableScope.create(env.enclClass.sym);
@Override
public void visitVarDef(JCVariableDecl tree) {
enclosedSymbols.enter(tree.sym);
super.visitVarDef(tree);
}
@Override
protected boolean trackable(VarSymbol sym) {
return !env.info.scope.includes(sym) &&
return enclosedSymbols.includes(sym) &&
sym.owner.kind == MTH;
}
}.analyzeTree(env, that);

View File

@ -0,0 +1,24 @@
/**
* @test
* @bug 8062747
* @summary Avoiding an error for lambdas with thrown types inference inside an anonymous class.
* @compile T8062747.java
*/
public class T8062747 {
public interface Throwing<Y extends Exception> {
void canThrow() throws Y;
}
public static <Y extends Exception> void wrap(Throwing<Y> action) {
}
public static void invoke(String a) {
Runnable r = new Runnable() {
@Override
public void run() {
wrap(() -> System.out.println(a));
}
};
}
}