Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8212117 Class.forName may return a reference to a loaded but not linked Class
  3. JDK-8230780

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

    XMLWordPrintable

    Details

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

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: