Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6939196

method handle signatures off the boot class path get linkage errors

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b01
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        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)
        */

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jrose John Rose
                Reporter:
                jrose John Rose
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: