7058630: JSR 292 method handle proxy violates contract for Object methods
authorjrose
Sat, 16 Jul 2011 15:40:13 -0700
changeset 10080 eb387b9bb282
parent 10079 0ed5b8d18ae4
child 10081 0f7b9636aa64
7058630: JSR 292 method handle proxy violates contract for Object methods Reviewed-by: never, twisti
jdk/src/share/classes/java/lang/invoke/MethodHandleProxies.java
jdk/test/java/lang/invoke/MethodHandlesTest.java
--- a/jdk/src/share/classes/java/lang/invoke/MethodHandleProxies.java	Wed Jul 13 01:40:55 2011 -0700
+++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleProxies.java	Sat Jul 16 15:40:13 2011 -0700
@@ -165,7 +165,7 @@
                         if (method.getDeclaringClass() == WrapperInstance.class)
                             return getArg(method.getName());
                         if (isObjectMethod(method))
-                            return callObjectMethod(this, method, args);
+                            return callObjectMethod(proxy, method, args);
                         throw new InternalError("bad proxy method: "+method);
                     }
                 }));
--- a/jdk/test/java/lang/invoke/MethodHandlesTest.java	Wed Jul 13 01:40:55 2011 -0700
+++ b/jdk/test/java/lang/invoke/MethodHandlesTest.java	Sat Jul 16 15:40:13 2011 -0700
@@ -2321,6 +2321,31 @@
             }
         }
     }
+
+    @Test
+    public void testRunnableProxy() throws Throwable {
+        if (CAN_SKIP_WORKING)  return;
+        startTest("testRunnableProxy");
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
+        MethodHandle run = lookup.findStatic(lookup.lookupClass(), "runForRunnable", MethodType.methodType(void.class));
+        Runnable r = MethodHandleProxies.asInterfaceInstance(Runnable.class, run);
+        testRunnableProxy(r);
+        assertCalled("runForRunnable");
+    }
+    private static void testRunnableProxy(Runnable r) {
+        //7058630: JSR 292 method handle proxy violates contract for Object methods
+        r.run();
+        Object o = r;
+        r = null;
+        boolean eq = (o == o);
+        int     hc = System.identityHashCode(o);
+        String  st = o.getClass().getName() + "@" + Integer.toHexString(hc);
+        Object expect = Arrays.asList(st, eq, hc);
+        if (verbosity >= 2)  System.out.println("expect st/eq/hc = "+expect);
+        Object actual = Arrays.asList(o.toString(), o.equals(o), o.hashCode());
+        if (verbosity >= 2)  System.out.println("actual st/eq/hc = "+actual);
+        assertEquals(expect, actual);
+    }
 }
 // Local abbreviated copy of sun.invoke.util.ValueConversions
 class ValueConversions {