This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
[ BUILD # : 201109070600 ] [ JDK VERSION : 1.7 ] The following Method handle test fails to run in NetBeans IDE 7.1 9/7 build: import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles.Lookup; import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodType.methodType; public class MethodHandleTest { public static void main(String... args) throws Throwable { methodHandleTest(); } private static void methodHandleTest() throws Throwable { final Lookup lookup = lookup(); MethodHandle multiply = lookup.findStatic(MethodHandleTest.class, "add", methodType(int.class, int.class, int.class)); System.out.println(multiply.invoke(3, 2)); // should print 5 } public static int add(int i, int j) { return i + j; } } The exception I get is: Exception in thread "main" java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(int,int)int to (Object[])Object at java.lang.invoke.MethodHandle.asType(MethodHandle.java:691) at java.lang.invoke.InvokeGeneric.dispatch(InvokeGeneric.java:103) at java.lang.invoke.InvokeGeneric.dispatchWithConversion(InvokeGeneric.java:117) at perf.MethodHandleTest.methodHandleTest(MethodHandleTest.java:32) at perf.MethodHandleTest.main(MethodHandleTest.java:26) Java Result: 1 This is a valid code and runs outside NetBeans IDE just fine.
Actually, I think the IDE can compile the code fine. The problem is that the code is OK with source level >= 1.7, but fails with that exception with source level <= 1.6 (in both cases this happens both inside and outside the IDE). The problem seems to be that when a source level changes, the project is not automatically reindexed - it is reindexed after a change in the given source root (or at the next IDE start/project reopening). As it is possible to listen on source level changes now, JavaCustomIndex (APTUtils?) should probably listen on them.
Fixed in jet-main. http://hg.netbeans.org/jet-main/rev/cf04f68bdb8c
Integrated into 'main-golden' Changeset: http://hg.netbeans.org/main-golden/rev/cf04f68bdb8c User: Dusan Balek <dbalek@netbeans.org> Log: Issue #201781: Unable to run method handles code in NetBeans IDE 7.1 nightly build - fixed.