< prev index next >

src/java.base/share/classes/java/lang/Class.java

Print this page

        

@@ -390,10 +390,14 @@
      *            {@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)

@@ -486,17 +490,25 @@
             cl = AccessController.doPrivileged(pa);
         } else {
             cl = module.getClassLoader();
         }
 
+        Class<?> ret;
         if (cl != null) {
-            return cl.loadClass(module, name);
+            ret = cl.loadClass(module, name);
         } else {
-            return BootLoader.loadClass(module, name);
+            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
      * has not already been initialized.
< prev index next >