JDK-7012087 : JSR 292 Misleading exception message for a non-bound MH for a virtual method
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: hs20
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-01-13
  • Updated: 2012-02-01
  • Resolved: 2011-04-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7Fixed hs21Fixed
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
EVALUATION John Rose said: Improve error message formatting to give more information to user. Also, catch a corner case related to 6930553 and 6844449.
11-04-2011

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

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

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