United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7012087 JSR 292 Misleading exception message for a non-bound MH for a virtual method
JDK-7012087 : JSR 292 Misleading exception message for a non-bound MH for a virtual method

Details
Type:
Bug
Submit Date:
2011-01-13
Status:
Closed
Updated Date:
2012-02-01
Project Name:
JDK
Resolved Date:
2011-04-25
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
hs20
Fixed Versions:
hs21 (b09)

Related Reports
Backport:

Sub Tasks

Description
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();
		}
	}

}
$

                                    

Comments
SUGGESTED FIX

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/file/tip/meth-err-7012087.patch
                                     
2011-03-30
EVALUATION

Yes; error message needs work.  See suggested fix.
                                     
2011-03-30
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/758ba0bf7bcc
                                     
2011-04-08
EVALUATION

John Rose said: Improve error message formatting to give more information to user.  Also, catch a corner case related to 6930553 and 6844449.
                                     
2011-04-11



Hardware and Software, Engineered to Work Together