Bug in invokeGeneric

Rémi Forax forax at univ-mlv.fr
Sun May 23 10:29:52 PDT 2010


Here is a test that doesn't pass with jdk7b94 (it's a regression).
It raises a WrongMethodTypeException.

The workaround is to convert the method handle to use a generic signature
(uncomment the line before the last line).

Exception in thread "main" java.dyn.WrongMethodTypeException: (II)Z 
cannot be called as 
(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     at MHInvokeGenericBug.main(MHInvokeGenericBug.java:19)


import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;

public class MHInvokeGenericBug {
   public boolean foo(int i, int i2) {
     return i == i2;
   }

   public static void main(String[] args) throws Throwable {
     MethodHandle mh = 
MethodHandles.lookup().findVirtual(MHInvokeGenericBug.class, "foo",
         MethodType.methodType(boolean.class, int.class, int.class));

     MHInvokeGenericBug bug = new MHInvokeGenericBug();

     //mh = mh.asType(MethodType.methodType(Object.class, Object.class, 
Object.class, Object.class));

     System.out.println(mh.invokeGeneric(bug, 27, 42));
   }
}


Rémi


More information about the mlvm-dev mailing list