Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7012087

JSR 292 Misleading exception message for a non-bound MH for a virtual method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: hs20
    • Fix Version/s: hs21
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b09
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

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

        }
        $

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jrose John Rose
                  Reporter:
                  kshiroko Kirill Shirokov (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: