< prev index next >
src/java.base/share/classes/java/lang/Class.java
Print this page
*** 390,399 ****
--- 390,403 ----
* {@code null}, and the caller does not have the
* {@link RuntimePermission}{@code ("getClassLoader")}
*
* @see java.lang.Class#forName(String)
* @see java.lang.ClassLoader
+ *
+ * @jls 12.2 Loading of Classes and Interfaces
+ * @jls 12.3 Linking of Classes and Interfaces
+ * @jls 12.4 Initialization of Classes and Interfaces
* @since 1.2
*/
@CallerSensitive
public static Class<?> forName(String name, boolean initialize,
ClassLoader loader)
*** 436,445 ****
--- 440,453 ----
* returns {@code null} after the class is loaded. </p>
*
* <p> This method does not check whether the requested class is
* accessible to its caller. </p>
*
+ * <p> Note that this method throws errors related to loading and linking as
+ * specified in Sections 12.2 and 12.3 of <em>The Java Language
+ * Specification</em>.
+ *
* @apiNote
* This method returns {@code null} on failure rather than
* throwing a {@link ClassNotFoundException}, as is done by
* the {@link #forName(String, boolean, ClassLoader)} method.
* The security check is a stack-based permission check if the caller
*** 463,472 ****
--- 471,482 ----
* permission check will be performed when a class loader calls
* {@link ModuleReader#open(String)} to read the bytes of a class file
* in a module.</li>
* </ul>
*
+ * @jls 12.2 Loading of Classes and Interfaces
+ * @jls 12.3 Linking of Classes and Interfaces
* @since 9
* @spec JPMS
*/
@CallerSensitive
public static Class<?> forName(Module module, String name) {
*** 486,501 ****
cl = AccessController.doPrivileged(pa);
} else {
cl = module.getClassLoader();
}
if (cl != null) {
! return cl.loadClass(module, name);
} else {
! return BootLoader.loadClass(module, name);
}
}
/**
* Creates a new instance of the class represented by this {@code Class}
* object. The class is instantiated as if by a {@code new}
* expression with an empty argument list. The class is initialized if it
--- 496,519 ----
cl = AccessController.doPrivileged(pa);
} else {
cl = module.getClassLoader();
}
+ Class<?> ret;
if (cl != null) {
! ret = cl.loadClass(module, name);
} else {
! ret = BootLoader.loadClass(module, name);
}
+ if (ret != null) {
+ // The loaded class should also be linked
+ linkClass(ret);
}
+ return ret;
+ }
+
+ private static native void linkClass(Class<?> c);
/**
* Creates a new instance of the class represented by this {@code Class}
* object. The class is instantiated as if by a {@code new}
* expression with an empty argument list. The class is initialized if it
< prev index next >