[9] RFR (S): 8036117: MethodHandles.catchException doesn't handle VarargsCollector right (8034120 failed) (original) (raw)

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Tue Mar 4 20:00:24 UTC 2014


http://cr.openjdk.java.net/~vlivanov/8036117/webrev.00/ https://bugs.openjdk.java.net/browse/JDK-8036117 84 lines changed: 74 ins; 3 del; 7 mod

I have to revert a cleanup I did for 8027827. MethodHandle.invokeWithArguments (and generic invocation) has unpleasant peculiarity in behavior when used with VarargsCollector. So, unfortunately, invokeWithArguments is not an option there.

Looking at the API (excerpts from javadoc [1] [2]), the following condition doesn't hold in that case: "trailing parameter type of the caller is a reference type identical to or assignable to the trailing parameter type of the adapter".

Example: target.invokeWithArguments((Object[])args) => target.invoke((Object)o1,(Object)o2,(Object)o3) =/> target.invokeExact((Object)o1, (Object)o2, (Object[])o3)

because Object !<: Object[].

The fix is to skip unnecessary conversion when invoking a method handle and just do a pairwise type conversion.

Testing: failing test case, nashorn w/ experimental features (octane)

Thanks!

Best regards, Vladimir Ivanov

[1] MethodHandle.invokeWithArguments "Performs a variable arity invocation, ..., as if via an inexact invoke from a call site which mentions only the type Object, and whose arity is the length of the argument array."

[2] MethodHandle.asVarargsCollector "When called with plain, inexact invoke, if the caller type is the same as the adapter, the adapter invokes the target as with invokeExact. (This is the normal behavior for invoke when types match.)

Otherwise, if the caller and adapter arity are the same, and the trailing parameter type of the caller is a reference type identical to or assignable to the trailing parameter type of the adapter, the arguments and return values are converted pairwise, as if by asType on a fixed arity method handle.

Otherwise, the arities differ, or the adapter's trailing parameter type is not assignable from the corresponding caller type. In this case, the adapter replaces all trailing arguments from the original trailing argument position onward, by a new array of type arrayType, whose elements comprise (in order) the replaced arguments."



More information about the core-libs-dev mailing list