提交 0059e8b2 编写于 作者: J jrose

7058630: JSR 292 method handle proxy violates contract for Object methods

Reviewed-by: never, twisti
上级 33062477
......@@ -165,7 +165,7 @@ public class MethodHandleProxies {
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);
}
}));
......
......@@ -2321,6 +2321,31 @@ public class MethodHandlesTest {
}
}
}
@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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册