Release Note: Classes are now loaded and linked by Class.forName()

XMLWordPrintable

    • Type: Sub-task
    • Resolution: Withdrawn
    • Priority: P4
    • None
    • Affects Version/s: 14
    • Component/s: core-libs
    • None

      The specification for `java.lang.Class.forName(String name, boolean initialize, ClassLoader loader)` has long stated, "this method attempts to locate, load, and link the class or interface."

      However, the class has not been linked when passing an `initialize` value of `false`. The following methods now ensure that linking is performed, conforming to the specification:
      * `java.lang.Class.forName(String, boolean, ClassLoader)`
      * `java.lang.Class.forName(Module, String)`
      * `java.lang.invoke.MethodHandles.Lookup.findClass(String)`

      These methods are declared to throw `LinkageError`. With this change, such errors may be thrown earlier (or perhaps they weren't thrown at all, e.g. for classes that are loaded but never used). For now, there is a VM flag, `-XX:+ClassForNameDeferLinking`, which can be used to revert to the previous behavior, in order to allow code to be fixed to account for undiscovered LinkageErrors.

            Assignee:
            Brent Christian
            Reporter:
            Brent Christian
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: