-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
7
-
generic
-
generic
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
"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
- duplicates
-
JDK-7044892 JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
- Closed
- relates to
-
JDK-7032323 code changes for JSR 292 EG adjustments to API, through Public Review
- Closed