[jdk17u-dev] RFR: 8280377: MethodHandleProxies does not correctly invoke default methods with varags

María Arias de Reyna duke at openjdk.org
Thu Mar 7 09:48:58 UTC 2024


On Mon, 26 Feb 2024 12:52:28 GMT, María Arias de Reyna <duke at openjdk.org> wrote:

> This is a backport of https://bugs.openjdk.org/browse/JDK-8280377 MethodHandleProxies does not correctly invoke default methods with varags
> 
> I applied the same fix that was applied to version 19 in https://github.com/openjdk/jdk/commit/a183bfb436a7dd998e602c2d16486e88c390fca1

src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java line 206:

> 204:                     if (isDefaultMethod(method)) {
> 205:                         // no additional access check is performed
> 206:                         return JLRA.invokeDefault(proxy, method, args, null);

As defined at the end of the file, `JavaLangReflectAccess JLRA = SharedSecrets.getJavaLangReflectAccess();` which is an interface implemented by `ReflectAccess.java` (modified below)

src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java line 323:

> 321:     }
> 322: 
> 323:     private static boolean hasDefaultMethods(Class<?> intfc) {

This piece of code is removed because it is no longer used. Now, instead of calling `callDefaultMethod(...)`, we are calling `Proxy.invokeDefault(...)` which is created on this same PR.

src/java.base/share/classes/java/lang/reflect/InvocationHandler.java line 264:

> 262:         Objects.requireNonNull(proxy);
> 263:         Objects.requireNonNull(method);
> 264:         return Proxy.invokeDefault(proxy, method, args, Reflection.getCallerClass());

This is where we call the previously removed piece of code.

src/java.base/share/classes/java/lang/reflect/InvocationHandler.java line 265:

> 263:         Objects.requireNonNull(proxy);
> 264:         Objects.requireNonNull(method);
> 265: 

This removed piece of code is moved to `Proxy.invokeDefault` (which is now called at the end of this removed code). The code moved is mostly the same, except it checks if the caller object is null. If it is  null, then it won't execute anything.

-------------

PR Review Comment: https://git.openjdk.org/jdk17u-dev/pull/2235#discussion_r1515850117
PR Review Comment: https://git.openjdk.org/jdk17u-dev/pull/2235#discussion_r1515857242
PR Review Comment: https://git.openjdk.org/jdk17u-dev/pull/2235#discussion_r1515847162
PR Review Comment: https://git.openjdk.org/jdk17u-dev/pull/2235#discussion_r1515846116


More information about the jdk-updates-dev mailing list