MethodHandle.bindTo chain fails with "IllegalArgumentException: no leading reference parameter"

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Tue Jul 25 17:21:28 UTC 2017


> Changing
>      MethodHandle mh2 = mh1.bindTo(test_vt);
> to
>      MethodHandle mh2 = MethodHandles.insertArguments(mh1, 0, test_vt);
> fails with:
> 
> Exception in thread "main" java.lang.ArrayStoreException: MyValue1
> 	at Test.test(Test.java:35)
> 	at Test.main(Test.java:41)
> 
> Why's that?

I'd say it's a problem in javac with auto-boxing of Q-types when calling 
vararg methods.

It tries to store a Q-typed value into an Object[] which generates an 
ArrayStoreException:

   long test() throws java.lang.Throwable;
...
         10: iconst_1
         11: anewarray     #7                  // class java/lang/Object
         14: dup
         15: iconst_0
         16: aload_0
         17: getfield      #3                  // Field test_vt:QMyValue1;
         20: aastore
         21: invokestatic  #8                  // Method 
java/lang/invoke/MethodHandles.insertArguments:(Ljava/lang/invoke/MethodHandle;I[Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;

Best regards,
Vladimir Ivanov


More information about the valhalla-dev mailing list