7058630: JSR 292 method handle proxy violates contract for Object methods
Reviewed-by: never, twisti
--- 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 {