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.
|