Community
Participate
Working Groups
Build Identifier: I20120608-1400 Eclipse compiler fails to implement the JLS regarding to the way MethodHandle.invokeExact should be compiled (section 15.12.3 of JLS7). The bug seams to only occur if invokeExact (and I suppose invoke) takes an array of Object as parameters. Reproducible: Always Steps to Reproduce: try to compile the following program using eclipse, it currently fails at runtime because invokeExact signature is compiled as (Object[])Object instead of (Object[])I. import static java.lang.invoke.MethodHandles.*; import java.lang.invoke.MethodHandle; public class EclipseInvokeExactBug { public static void main(String[] args) throws Throwable { MethodHandle mh = dropArguments(insertArguments(identity(int.class), 0, 42), 0, Object[].class); int value = (int)mh.invokeExact(new Object[0]); } } Here is the corresponding bytecode: public static void main(java.lang.String[]) throws java.lang.Throwable; Code: 0: getstatic #19 // Field java/lang/Integer.TYPE:Ljava/lang/Class; 3: invokestatic #25 // Method java/lang/invoke/MethodHandles.identity:(Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle; 6: iconst_0 7: iconst_1 8: anewarray #3 // class java/lang/Object 11: dup 12: iconst_0 13: bipush 42 15: invokestatic #31 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 18: aastore 19: invokestatic #35 // Method java/lang/invoke/MethodHandles.insertArguments:(Ljava/lang/invoke/MethodHandle;I[Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle; 22: iconst_0 23: iconst_1 24: anewarray #39 // class java/lang/Class 27: dup 28: iconst_0 29: ldc #41 // class "[Ljava/lang/Object;" 31: aastore 32: invokestatic #43 // Method java/lang/invoke/MethodHandles.dropArguments:(Ljava/lang/invoke/MethodHandle;I[Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle; 35: astore_1 36: aload_1 37: iconst_0 38: anewarray #3 // class java/lang/Object 41: invokevirtual #47 // Method java/lang/invoke/MethodHandle.invokeExact:([Ljava/lang/Object;)Ljava/lang/Object; 44: checkcast #20 // class java/lang/Integer 47: invokevirtual #53 // Method java/lang/Integer.intValue:()I 50: istore_2 51: return } as you can see the descriptor of invokevirtual at bytecode 41 is wrong.
I think the fix is trivial. The method binding for invokeExact(..) is not a PolymorphicMethodBinding.
Created attachment 218879 [details] Proposed fix
Created attachment 218880 [details] Regression test
I think this is a good candidate for 3.8.1 as there is no workaround to get the right method binding.
Thanks Olivier! I'll release it for 3.8.1
Released in master via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=93f7bdc9db07b3d133a0d0cb74ca50592e6517b1
Reviewed the patch and released in R3_8_maintenance via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R3_8_maintenance&id=6c8426c089e0f0c1552bad64f3deb5fdf6dfbdec
Verified for 4.3 M1 using Build id: I20120805-2000
Verified for 3.8.1 using Build id: M20120809-1000