Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
The following test program throws an error on the marked line. The problem is a weakness in the current JSR 292 Reference Implementation logic for resolving MethodTypes that mention types not on the boot class path. The workaround, therefore, is to load your entire JSR 292 application using -Xbootclasspath/a:myapp.jar. import java.dyn.*; import static java.dyn.MethodHandles.*; import static java.dyn.MethodType.*; public class BCPBug { // Local class which appears in method signature; static class Example { } static void bcpTypesOnly(Object x) { System.out.println("bcpTypesOnly"); } static void hasUserType(Example x) { System.out.println("hasUserType"); } public static void main(String... av) throws Throwable { Lookup lookup = lookup(); MethodHandle bcpTypesOnly = lookup.findStatic(lookup.lookupClass(), "bcpTypesOnly", methodType(void.class, Object.class)); MethodHandle hasUserType = lookup.findStatic(lookup.lookupClass(), "hasUserType", methodType(void.class, Example.class)); bcpTypesOnly.<void>invokeExact((Object)null); hasUserType.<void>invokeExact((Example)null); // throws NoClassDefFoundError on BCPBug$Example } } /* Run: $ $JAVA7X_HOME/bin/javac -d . BCPBug.java $ $JAVA7X_HOME/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -cp . BCPBug bcpTypesOnly Exception in thread "main" java.lang.NoClassDefFoundError: BCPBug$Example at BCPBug.main(BCPBug.java:17) */
|