changeset 1132:cb09efd9e158

Fix: access to final variables from lambda expressions is erroneously rejected Un-ignore previously ignored test LambdaCapture05.java
author mcimadamore
date Thu, 14 Jul 2011 11:10:07 +0100
parents 397b7ba6e0b9
children a7e6203a332d
files src/share/classes/com/sun/tools/javac/comp/Flow.java test/tools/javac/lambda/LambdaCapture05.java test/tools/javac/lambda/LambdaExpr08.java
diffstat 3 files changed, 43 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Wed Jul 13 12:14:17 2011 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Thu Jul 14 11:10:07 2011 +0100
@@ -453,7 +453,7 @@
         if (currentLambda != null &&
                 sym.owner.kind == MTH &&
                 sym.owner != currentLambda &&
-                (sym.flags() & EFFECTIVELY_FINAL) == 0) {
+                (sym.flags() & (FINAL | EFFECTIVELY_FINAL)) == 0) {
             log.error(pos, "cant.ref.non.effectively.final.var",
                     sym);
         }
--- a/test/tools/javac/lambda/LambdaCapture05.java	Wed Jul 13 12:14:17 2011 +0100
+++ b/test/tools/javac/lambda/LambdaCapture05.java	Thu Jul 14 11:10:07 2011 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,6 @@
 
 /*
  * @test
- * @ignore
  * @summary test for capture in nested lambda expressions
  * @author  Maurizio Cimadamore
  * @run main LambdaCapture05
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaExpr08.java	Thu Jul 14 11:10:07 2011 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary check that reference to local final variable w/o initializer is accepted
+ * @compile LambdaExpr08.java
+ */
+
+class LambdaExpr08 {
+
+    interface SAM {
+       String m();
+    }
+
+    void test() {
+        final String s;
+        s = "";
+        SAM sam = #{ -> s };
+    }
+}