8024809: javac, some lambda programs are rejected by flow analysis

Sat, 19 Oct 2013 17:43:09 +0100

author
vromero
date
Sat, 19 Oct 2013 17:43:09 +0100
changeset 2148
c4292590fc70
parent 2147
130b8c0e570e
child 2149
e5d3cd43c85e

8024809: javac, some lambda programs are rejected by flow analysis
Reviewed-by: jjg, dlsmith

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8016081/T8016081.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/LambdaExpr13.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTesta.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTesta.out file | annotate | diff | comparison | revisions
test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTestb.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTestb.out file | annotate | diff | comparison | revisions
test/tools/javac/lambda/TestSelfRef.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Oct 18 16:34:42 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sat Oct 19 17:43:09 2013 +0100
     1.3 @@ -314,9 +314,6 @@
     1.4                  case CLASSDEF:
     1.5                      //class def is always an owner
     1.6                      return ((JCClassDecl)env.tree).sym;
     1.7 -                case LAMBDA:
     1.8 -                    //a lambda is an owner - return a fresh synthetic method symbol
     1.9 -                    return new MethodSymbol(0, names.empty, null, syms.methodClass);
    1.10                  case BLOCK:
    1.11                      //static/instance init blocks are owner
    1.12                      Symbol blockSym = env.info.scope.owner;
     2.1 --- a/test/tools/javac/lambda/8016081/T8016081.java	Fri Oct 18 16:34:42 2013 -0700
     2.2 +++ b/test/tools/javac/lambda/8016081/T8016081.java	Sat Oct 19 17:43:09 2013 +0100
     2.3 @@ -32,7 +32,7 @@
     2.4      interface fint { int get(); }
     2.5  
     2.6      @interface atype {
     2.7 -        fint fld = ()->( fld == null ?0 : 1);
     2.8 +        fint fld = ()->1;
     2.9      }
    2.10  
    2.11      @atype class T {}
     3.1 --- a/test/tools/javac/lambda/LambdaExpr13.java	Fri Oct 18 16:34:42 2013 -0700
     3.2 +++ b/test/tools/javac/lambda/LambdaExpr13.java	Sat Oct 19 17:43:09 2013 +0100
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -26,13 +26,14 @@
    3.11   * @bug 8003280
    3.12   * @summary Add lambda tests
    3.13   *  check that recursive lambda (through field ref) is accepted in all contexts
    3.14 + *  but field initialization
    3.15   * @compile LambdaExpr13.java
    3.16   */
    3.17  
    3.18  class LambdaExpr13 {
    3.19  
    3.20 -    Runnable ir = () -> { ir.run(); };;
    3.21 -    static Runnable sr = () -> { sr.run(); };
    3.22 +    Runnable ir;
    3.23 +    static Runnable sr;
    3.24  
    3.25      { ir = () -> { ir.run(); }; }
    3.26      static { sr = () -> { sr.run(); }; }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTesta.java	Sat Oct 19 17:43:09 2013 +0100
     4.3 @@ -0,0 +1,65 @@
     4.4 +/*
     4.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @bug 8024809
    4.30 + * @summary javac, some lambda programs are rejected by flow analysis
    4.31 + * @compile/fail/ref=SelfInitializerInLambdaTesta.out -XDrawDiagnostics SelfInitializerInLambdaTesta.java
    4.32 + */
    4.33 +
    4.34 +public class SelfInitializerInLambdaTesta {
    4.35 +
    4.36 +    final Runnable r1 = ()->System.out.println(r1);
    4.37 +
    4.38 +    final Object lock = new Object();
    4.39 +
    4.40 +    final Runnable r2 = ()->{
    4.41 +        System.out.println(r2);
    4.42 +        synchronized (lock){}
    4.43 +    };
    4.44 +
    4.45 +    final Runnable r3 = ()->{
    4.46 +        synchronized (lock){
    4.47 +            System.out.println(r3);
    4.48 +        }
    4.49 +    };
    4.50 +
    4.51 +    final Runnable r4 = ()->{
    4.52 +        System.out.println(r4);
    4.53 +    };
    4.54 +
    4.55 +    interface SAM {
    4.56 +        int m(String s);
    4.57 +    }
    4.58 +
    4.59 +    final SAM s1 = (String s)->{
    4.60 +        System.out.println(s + s1.toString());
    4.61 +        return 0;
    4.62 +    };
    4.63 +
    4.64 +    final SAM s2 = (s)->{
    4.65 +        System.out.println(s + s2.toString());
    4.66 +        return 0;
    4.67 +    };
    4.68 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTesta.out	Sat Oct 19 17:43:09 2013 +0100
     5.3 @@ -0,0 +1,7 @@
     5.4 +SelfInitializerInLambdaTesta.java:33:48: compiler.err.illegal.self.ref
     5.5 +SelfInitializerInLambdaTesta.java:38:28: compiler.err.illegal.self.ref
     5.6 +SelfInitializerInLambdaTesta.java:44:32: compiler.err.illegal.self.ref
     5.7 +SelfInitializerInLambdaTesta.java:49:28: compiler.err.illegal.self.ref
     5.8 +SelfInitializerInLambdaTesta.java:57:32: compiler.err.illegal.self.ref
     5.9 +SelfInitializerInLambdaTesta.java:62:32: compiler.err.illegal.self.ref
    5.10 +6 errors
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTestb.java	Sat Oct 19 17:43:09 2013 +0100
     6.3 @@ -0,0 +1,40 @@
     6.4 +/*
     6.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test
    6.29 + * @bug 8024809
    6.30 + * @summary javac, some lambda programs are rejected by flow analysis
    6.31 + * @compile/fail/ref=SelfInitializerInLambdaTestb.out -XDrawDiagnostics SelfInitializerInLambdaTestb.java
    6.32 + */
    6.33 +
    6.34 +public class SelfInitializerInLambdaTestb {
    6.35 +
    6.36 +    final Runnable r1;
    6.37 +
    6.38 +    final Runnable r2 = ()-> System.out.println(r1);
    6.39 +
    6.40 +    SelfInitializerInLambdaTestb() {
    6.41 +        r1 = ()->System.out.println(r1);
    6.42 +    }
    6.43 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/lambda/T8024809/SelfInitializerInLambdaTestb.out	Sat Oct 19 17:43:09 2013 +0100
     7.3 @@ -0,0 +1,3 @@
     7.4 +SelfInitializerInLambdaTestb.java:35:49: compiler.err.var.might.not.have.been.initialized: r1
     7.5 +SelfInitializerInLambdaTestb.java:38:37: compiler.err.var.might.not.have.been.initialized: r1
     7.6 +2 errors
     8.1 --- a/test/tools/javac/lambda/TestSelfRef.java	Fri Oct 18 16:34:42 2013 -0700
     8.2 +++ b/test/tools/javac/lambda/TestSelfRef.java	Sat Oct 19 17:43:09 2013 +0100
     8.3 @@ -1,5 +1,5 @@
     8.4  /*
     8.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     8.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     8.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.8   *
     8.9   * This code is free software; you can redistribute it and/or modify it
    8.10 @@ -29,7 +29,6 @@
    8.11   *          consistently w.r.t. local inner classes
    8.12   */
    8.13  
    8.14 -import com.sun.source.util.JavacTask;
    8.15  import java.net.URI;
    8.16  import java.util.Arrays;
    8.17  import javax.tools.Diagnostic;
    8.18 @@ -38,6 +37,7 @@
    8.19  import javax.tools.SimpleJavaFileObject;
    8.20  import javax.tools.StandardJavaFileManager;
    8.21  import javax.tools.ToolProvider;
    8.22 +import com.sun.source.util.JavacTask;
    8.23  
    8.24  public class TestSelfRef {
    8.25  
    8.26 @@ -176,10 +176,16 @@
    8.27          check();
    8.28      }
    8.29  
    8.30 +    boolean isErrorExpected() {
    8.31 +        //illegal forward ref
    8.32 +        boolean result = ik.inMethodContext(sk) && (rk.selfRef || rk.forwardRef);
    8.33 +        result |= (rk == RefKind.SELF_LAMBDA || rk == RefKind.FORWARD_LAMBDA);
    8.34 +        return result;
    8.35 +    }
    8.36 +
    8.37      void check() {
    8.38 -        //illegal forward ref
    8.39 -        boolean errorExpected = ik.inMethodContext(sk) &&
    8.40 -                (rk.selfRef || rk.forwardRef);
    8.41 +        checkCount++;
    8.42 +        boolean errorExpected = isErrorExpected();
    8.43          if (diagChecker.errorFound != errorExpected) {
    8.44              throw new Error("invalid diagnostics for source:\n" +
    8.45                  source.getCharContent(true) +

mercurial