It's not possible to call MethodHandle.invokeExact() from JNI code.
When I try to get method ID and pass actual MH signature to JNI function GetMethodID, for example:
mid = GetMethodID(..., methodHandleClass, "invokeExact", "(Ljava/lang/Object;Ljava/lang/Object;IJDF)Ljava/lang/Object;");
...NoSuchMethodError is reported by JNI.
Note that invokeExact calls encoded into classfiles created by JDK7 b123 javac, has actual MH signature, and NOT the signature recorded in MethodHandle.class for invokeExact: ("([Ljava/lang/Object;)Ljava/lang/Object;").
According to the lastest JSR 292 specification, this is not a defect.
According to documentation for MethodHandle.invokeExact() method:
"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, via JNI, or indirectly via java.lang.invoke.MethodHandles.Lookup#unreflect, it will throw an UnsupportedOperationException."
Only MethodHandle.invokeWithArguments() can be used to call MethodHandle target from JNI and Reflection code.
When I try to get method ID and pass actual MH signature to JNI function GetMethodID, for example:
mid = GetMethodID(..., methodHandleClass, "invokeExact", "(Ljava/lang/Object;Ljava/lang/Object;IJDF)Ljava/lang/Object;");
...NoSuchMethodError is reported by JNI.
Note that invokeExact calls encoded into classfiles created by JDK7 b123 javac, has actual MH signature, and NOT the signature recorded in MethodHandle.class for invokeExact: ("([Ljava/lang/Object;)Ljava/lang/Object;").
According to the lastest JSR 292 specification, this is not a defect.
According to documentation for MethodHandle.invokeExact() method:
"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, via JNI, or indirectly via java.lang.invoke.MethodHandles.Lookup#unreflect, it will throw an UnsupportedOperationException."
Only MethodHandle.invokeWithArguments() can be used to call MethodHandle target from JNI and Reflection code.