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

Fri, 14 Nov 2014 20:27:08 +0100

author
jlahoda
date
Fri, 14 Nov 2014 20:27:08 +0100
changeset 2606
f7f3f96999ba
parent 2603
682a6c1aefd7
child 2607
10e9228e77b0

8062747: Compiler error when anonymous class uses method with parametrized exception
Summary: When inferring lambda's thrown types, avoid tracking variables that are not under the lambda to avoid crashes.
Reviewed-by: vromero

src/share/classes/com/sun/tools/javac/comp/Flow.java file | annotate | diff | comparison | revisions
test/tools/javac/flow/T8062747.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Fri Nov 14 09:48:02 2014 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Fri Nov 14 20:27:08 2014 +0100
     1.3 @@ -242,9 +242,15 @@
     1.4          Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
     1.5          try {
     1.6              new AssignAnalyzer() {
     1.7 +                Scope enclosedSymbols = new Scope(env.enclClass.sym);
     1.8 +                @Override
     1.9 +                public void visitVarDef(JCVariableDecl tree) {
    1.10 +                    enclosedSymbols.enter(tree.sym);
    1.11 +                    super.visitVarDef(tree);
    1.12 +                }
    1.13                  @Override
    1.14                  protected boolean trackable(VarSymbol sym) {
    1.15 -                    return !env.info.scope.includes(sym) &&
    1.16 +                    return enclosedSymbols.includes(sym) &&
    1.17                             sym.owner.kind == MTH;
    1.18                  }
    1.19              }.analyzeTree(env, that);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/flow/T8062747.java	Fri Nov 14 20:27:08 2014 +0100
     2.3 @@ -0,0 +1,24 @@
     2.4 +/**
     2.5 + * @test
     2.6 + * @bug 8062747
     2.7 + * @summary Avoiding an error for lambdas with thrown types inference inside an anonymous class.
     2.8 + * @compile T8062747.java
     2.9 + */
    2.10 +public class T8062747 {
    2.11 +
    2.12 +    public interface Throwing<Y extends Exception> {
    2.13 +        void canThrow() throws Y;
    2.14 +    }
    2.15 +
    2.16 +    public static <Y extends Exception> void wrap(Throwing<Y> action) {
    2.17 +    }
    2.18 +
    2.19 +    public static void invoke(String a) {
    2.20 +        Runnable r = new Runnable() {
    2.21 +            @Override
    2.22 +            public void run() {
    2.23 +                wrap(() -> System.out.println(a));
    2.24 +            }
    2.25 +        };
    2.26 +    }
    2.27 +}

mercurial