JDK-7042656 : JSR292: invokeExact/Generic doesn't throw UnsupportedOperationException if invoked via Method.invoke
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2011-05-06
  • Updated: 2012-03-22
  • Resolved: 2011-05-14
Related Reports
Duplicate :  
Relates :  
Description
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

Comments
EVALUATION Correct. Requires a small JVM change to fix.
13-05-2011