RFR: 8280377: MethodHandleProxies does not correctly invoke default methods with varags
Mandy Chung
mchung at openjdk.java.net
Mon Jan 24 23:05:23 UTC 2022
On Sat, 22 Jan 2022 21:48:38 GMT, Johannes Kuhn <jkuhn at openjdk.org> wrote:
>> The MethodHandle of a default method should be made as a fixed arity method handle because it is invoked via Proxy's invocation handle with a non-vararg array of arguments. On the other hand, the `InvocationHandle::invokeDefault` method was added in Java 16 to invoke a default method of a proxy instance. This patch simply converts the implementation to call `InvocationHandle::invokeDefault` instead.
>
> When testing this patch from a named module and not-exported package, I get the following exception:
>
>
> Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
> at jdk.proxy1/com.sun.proxy.jdk.proxy1.$Proxy0.toString(Unknown Source)
> at test.openjdk/test.openjdk.ProxyTest.main(ProxyTest.java:22)
> Caused by: java.lang.IllegalAccessException: class java.lang.invoke.MethodHandleProxies$1 (in module java.base) cannot access interface test.openjdk.ProxyTest$Test (in module test.openjdk) because module test.openjdk does not export test.openjdk to module java.base
> at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:394)
> at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
> at java.base/java.lang.reflect.InvocationHandler.invokeDefault(InvocationHandler.java:278)
> at java.base/java.lang.invoke.MethodHandleProxies$1.invoke(MethodHandleProxies.java:202)
> ... 2 more
>
>
> [My test code](https://gist.github.com/DasBrain/60dbc1c9075b15635d9c87e8295f1c1a).
> Running without the patch results in the wrong output for default varargs methods, so this is a regression.
@DasBrain thanks for catching this. `MethodHandleProxies::asInterfaceInstance` should perform no additional access checks other than checking the interface is public and not sealed, as specified in the spec.
The patch is updated.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7185
More information about the core-libs-dev
mailing list