Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2209155 | 7 | John Rose | P4 | Closed | Fixed | b139 |
If I try to call method handle for a virtual method without binding it to an object, the exception message says the following:
java.dyn.WrongMethodTypeException: (Ljava/lang/String;Ljava/lang/Integer;F)J cannot be called as (Ljava/lang/String;Ljava/lang/Integer;F)J
at jsr292test01.main(jsr292test01.java:24)
This is confusing for a user: signatures do match, why wrong type?
Test program:
$ cat jsr292test01.java
import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;
public class jsr292test01 {
public long method(String a, Integer b, float c) {
return 0;
}
public static void main(String[] args) {
try {
MethodHandle mh = MethodHandles.lookup().findVirtual(jsr292test01.class, "method",
MethodType.methodType(long.class, String.class, Integer.class, float.class));
jsr292test01 me = new jsr292test01();
long l;
System.err.println("1");
l = (long) mh.bindTo(me).invokeExact("a", new Integer(1), 3F); // OK
System.err.println("2");
l = (long) mh.invokeExact("a", new Integer(1), 3F); // Exception
} catch ( Throwable t ) {
t.printStackTrace();
}
}
}
$
java.dyn.WrongMethodTypeException: (Ljava/lang/String;Ljava/lang/Integer;F)J cannot be called as (Ljava/lang/String;Ljava/lang/Integer;F)J
at jsr292test01.main(jsr292test01.java:24)
This is confusing for a user: signatures do match, why wrong type?
Test program:
$ cat jsr292test01.java
import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;
public class jsr292test01 {
public long method(String a, Integer b, float c) {
return 0;
}
public static void main(String[] args) {
try {
MethodHandle mh = MethodHandles.lookup().findVirtual(jsr292test01.class, "method",
MethodType.methodType(long.class, String.class, Integer.class, float.class));
jsr292test01 me = new jsr292test01();
long l;
System.err.println("1");
l = (long) mh.bindTo(me).invokeExact("a", new Integer(1), 3F); // OK
System.err.println("2");
l = (long) mh.invokeExact("a", new Integer(1), 3F); // Exception
} catch ( Throwable t ) {
t.printStackTrace();
}
}
}
$
- backported by
-
JDK-2209155 JSR 292 Misleading exception message for a non-bound MH for a virtual method
- Closed