changeset 4382:bfc5ec581c48

7058630: JSR 292 method handle proxy violates contract for Object methods Reviewed-by: never, twisti
author jrose
date Sat, 16 Jul 2011 15:40:13 -0700
parents 5f3cd0cbad56
children 668edf27e9c7
files src/share/classes/java/lang/invoke/MethodHandleProxies.java test/java/lang/invoke/MethodHandlesTest.java
diffstat 2 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/MethodHandleProxies.java	Wed Jul 13 01:40:55 2011 -0700
+++ b/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/test/java/lang/invoke/MethodHandlesTest.java	Wed Jul 13 01:40:55 2011 -0700
+++ b/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 {