changeset 2010:b0716aee0da8

8012556: Implement lambda methods on interfaces as static 8006140: Javac NPE compiling Lambda expression on initialization expression of static field in interface
author rfield
date Wed, 17 Apr 2013 19:54:16 -0700
parents f8c62319e8b8
children ae6493366e11
files src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java test/tools/javac/lambda/LambdaInterfaceStaticField.java test/tools/javac/lambda/bytecode/TestLambdaBytecode.java
diffstat 3 files changed, 45 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Apr 16 16:47:03 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Apr 17 19:54:16 2013 -0700
@@ -1719,12 +1719,13 @@
                 }
                 boolean inInterface = translatedSym.owner.isInterface();
                 boolean thisReferenced = !getSymbolMap(CAPTURED_THIS).isEmpty();
-                boolean needInstance = thisReferenced || inInterface;
 
-                // If instance access isn't needed, make it static
-                // Interface methods much be public default methods, otherwise make it private
-                translatedSym.flags_field = SYNTHETIC | (needInstance? 0 : STATIC) |
-                        (inInterface? PUBLIC | DEFAULT : PRIVATE);
+                // If instance access isn't needed, make it static.
+                // Interface instance methods must be default methods.
+                // Awaiting VM channges, interface methods are public
+                translatedSym.flags_field = SYNTHETIC | 
+                        (inInterface? PUBLIC : PRIVATE) | 
+                        (thisReferenced? (inInterface? DEFAULT : 0) : STATIC);
 
                 //compute synthetic params
                 ListBuffer<JCVariableDecl> params = ListBuffer.lb();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaInterfaceStaticField.java	Wed Apr 17 19:54:16 2013 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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
+ * @bug 8006140
+ * @summary Javac NPE compiling Lambda expression on initialization expression of static field in interface
+ * @compile LambdaInterfaceStaticField.java
+ */
+
+interface LambdaInterfaceStaticField {
+  interface I {
+     int m();
+  }
+  public static final I fld = () -> 5;
+}
--- a/test/tools/javac/lambda/bytecode/TestLambdaBytecode.java	Tue Apr 16 16:47:03 2013 +0100
+++ b/test/tools/javac/lambda/bytecode/TestLambdaBytecode.java	Wed Apr 17 19:54:16 2013 -0700
@@ -306,7 +306,7 @@
     String makeIndyType(int id) {
         StringBuilder buf = new StringBuilder();
         buf.append("(");
-        if (!mk2.isStatic() || mk1.inInterface()) {
+        if (!mk2.isStatic()) {
             buf.append(String.format("LTest%d;", id));
         }
         buf.append(")Ljava/lang/Runnable;");