The javadoc for the MethodHandle invokeExact/invokeGeneric methods states as follows:
"When this method is observed via the Core Reflection API, it will appear as a single
native method, taking an object array and returning an object. If this native method
is invoked directly via Method.invoke ... it will throw an UnsupportedOperationException."
However, InvocationTargetException is thrown in such cases. Please see the minimized test below
to reproduce the issue.
Minimized test:
===============
$ cat test.java
import java.lang.reflect.*;
import java.lang.invoke.*;
public class test {
public static void main(String[] args) throws Throwable {
MethodHandle target = MethodHandles.lookup().findVirtual(
MethodHandle.class, "invokeExact",
MethodType.methodType(Object.class, Object[].class));
Method method = MethodHandle.class.getDeclaredMethod(
"invokeExact", Object[].class);
//Method method = MethodHandle.class.getDeclaredMethod(
// "invokeGeneric", Object[].class);
Object[] params = new Object[1];
method.invoke(target, params);
}
}
Minimized test output:
========================
$ javac test.java
$ java -verify test
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at test.main(test.java:15)
Caused by: java.lang.UnsatisfiedLinkError: java.lang.invoke.MethodHandle.invokeExact([Ljava/lang/Object;)Ljava/lang/Object;
at java.lang.invoke.MethodHandle.invokeExact(Native Method)
... 5 more