changeset 661:52681eb717e7

Bug fixes: *) proxied lambdas/method refs do not behave consistently with Object.equals() [kudos to Remi for the fix] *) SAM conversion should not box/unbox lambda parameter type (i.e. a lambda acceoting an int cannot be SAM-converted to a method accepting Integer)
author mcimadamore
date Sat, 18 Sep 2010 15:03:28 -0700
parents c572fa185d05
children 13e106a36674
files src/share/classes/com/sun/runtime/ProxyHelper.java src/share/classes/com/sun/tools/javac/code/Types.java test/tools/javac/lambda/LambdaConv10.java test/tools/javac/lambda/LambdaConv10.out test/tools/javac/lambda/MethodReference13.java
diffstat 5 files changed, 92 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/runtime/ProxyHelper.java	Mon Sep 06 15:01:38 2010 +0100
+++ b/src/share/classes/com/sun/runtime/ProxyHelper.java	Sat Sep 18 15:03:28 2010 -0700
@@ -41,7 +41,7 @@
             @Override
             public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                 if (method.getDeclaringClass() == Object.class) {
-                    return dispatchObjectMethod(method, args);
+                    return dispatchObjectMethod(proxy, method, args);
                 }
                 else {
                     Object[] args1 = null;
@@ -62,11 +62,11 @@
                 }
             }
 
-            Object dispatchObjectMethod(Method method, Object... args) throws Throwable {
+            Object dispatchObjectMethod(Object proxy, Method method, Object... args) throws Throwable {
                 if (method.getName().equals("hashCode")) {
                     return hashCode();
                 } else if (method.getName().equals("equals")) {
-                    return equals(args[0]);
+                    return proxy == args[0];
                 } else if (method.getName().equals("toString")) {
                     return toString();
                 } else {
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Sep 06 15:01:38 2010 +0100
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Sat Sep 18 15:03:28 2010 -0700
@@ -319,7 +319,7 @@
 
             boolean argsOk = t.getParameterTypes().size() == mtype.getParameterTypes().size() && (
                 isSameTypes(mtype.getParameterTypes(), t.getParameterTypes()) ||
-                containsType(mtype.getParameterTypes(), boxedTypesOrTypes(t.getParameterTypes())));
+                containsType(mtype.getParameterTypes(), t.getParameterTypes()));
 
             boolean thrownOk = t.getThrownTypes() == Type.noTypes ||
                     chk.unhandled(t.getThrownTypes(), mtype.getThrownTypes()).isEmpty();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaConv10.java	Sat Sep 18 15:03:28 2010 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010, 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 lambda conversion does not allow boxing of lambda parameters
+ * @author  Maurizio Cimadamore
+ * @compile/fail/ref=LambdaConv10.out -XDrawDiagnostics LambdaConv10.java
+ */
+
+class LambdaConv10 {
+
+    interface Method1<R, A1, throws E> { public R call( A1 a1 ) throws E; }
+
+    public static void main( final String... notUsed ) throws Throwable {
+        Method1<Integer,Integer,void> m1 = #( int i ) { 2 * i };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaConv10.out	Sat Sep 18 15:03:28 2010 -0700
@@ -0,0 +1,2 @@
+LambdaConv10.java:36:44: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.incompatible.target.in.lambda.conv: call, kindname.interface, LambdaConv10.Method1)), #java.lang.Integer(int)(), LambdaConv10.Method1<java.lang.Integer,java.lang.Integer,>
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/MethodReference13.java	Sat Sep 18 15:03:28 2010 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2010, 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 equals() on Proxied objects is handled accordingly
+ * @author  Maurizio Cimadamore
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles MethodReference13
+ */
+
+public class MethodReference13 {
+
+    static void assertTrue(boolean cond) {
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    interface SAM {
+        void m();
+    }
+
+    static void m() { }
+
+    public static void main(String[] args) {
+        SAM s = MethodReference13#m;
+        assertTrue(s.equals(s));
+    }
+}