src/java.base/share/classes/java/lang/ClassLoader.java
changeset 48066 df95bd1fd4b1
parent 47951 a1f88c937a77
child 48205 6cd25cd7df81
equal deleted inserted replaced
48065:c4f2b6749c86 48066:df95bd1fd4b1
    28 import java.io.InputStream;
    28 import java.io.InputStream;
    29 import java.io.IOException;
    29 import java.io.IOException;
    30 import java.io.UncheckedIOException;
    30 import java.io.UncheckedIOException;
    31 import java.io.File;
    31 import java.io.File;
    32 import java.lang.reflect.Constructor;
    32 import java.lang.reflect.Constructor;
       
    33 import java.lang.reflect.InvocationTargetException;
    33 import java.net.URL;
    34 import java.net.URL;
    34 import java.security.AccessController;
    35 import java.security.AccessController;
    35 import java.security.AccessControlContext;
    36 import java.security.AccessControlContext;
    36 import java.security.CodeSource;
    37 import java.security.CodeSource;
    37 import java.security.PrivilegedAction;
    38 import java.security.PrivilegedAction;
  1865      * instance is then created using this constructor with the default system
  1866      * instance is then created using this constructor with the default system
  1866      * class loader as the parameter.  The resulting class loader is defined
  1867      * class loader as the parameter.  The resulting class loader is defined
  1867      * to be the system class loader. During construction, the class loader
  1868      * to be the system class loader. During construction, the class loader
  1868      * should take great care to avoid calling {@code getSystemClassLoader()}.
  1869      * should take great care to avoid calling {@code getSystemClassLoader()}.
  1869      * If circular initialization of the system class loader is detected then
  1870      * If circular initialization of the system class loader is detected then
  1870      * an unspecified error or exception is thrown.
  1871      * an {@code IllegalStateException} is thrown.
  1871      *
  1872      *
  1872      * @implNote The system property to override the system class loader is not
  1873      * @implNote The system property to override the system class loader is not
  1873      * examined until the VM is almost fully initialized. Code that executes
  1874      * examined until the VM is almost fully initialized. Code that executes
  1874      * this method during startup should take care not to cache the return
  1875      * this method during startup should take care not to cache the return
  1875      * value until the system is fully initialized.
  1876      * value until the system is fully initialized.
  1916             case 1:
  1917             case 1:
  1917             case 2:
  1918             case 2:
  1918                 // the system class loader is the built-in app class loader during startup
  1919                 // the system class loader is the built-in app class loader during startup
  1919                 return getBuiltinAppClassLoader();
  1920                 return getBuiltinAppClassLoader();
  1920             case 3:
  1921             case 3:
  1921                 String msg = "getSystemClassLoader should only be called after VM booted";
  1922                 String msg = "getSystemClassLoader cannot be called during the system class loader instantiation";
  1922                 throw new InternalError(msg);
  1923                 throw new IllegalStateException(msg);
  1923             case 4:
  1924             case 4:
  1924                 // system fully initialized
  1925                 // system fully initialized
  1925                 assert VM.isBooted() && scl != null;
  1926                 assert VM.isBooted() && scl != null;
  1926                 SecurityManager sm = System.getSecurityManager();
  1927                 SecurityManager sm = System.getSecurityManager();
  1927                 if (sm != null) {
  1928                 if (sm != null) {
  1967                 // custom class loader is only supported to be loaded from unnamed module
  1968                 // custom class loader is only supported to be loaded from unnamed module
  1968                 Constructor<?> ctor = Class.forName(cn, false, builtinLoader)
  1969                 Constructor<?> ctor = Class.forName(cn, false, builtinLoader)
  1969                                            .getDeclaredConstructor(ClassLoader.class);
  1970                                            .getDeclaredConstructor(ClassLoader.class);
  1970                 scl = (ClassLoader) ctor.newInstance(builtinLoader);
  1971                 scl = (ClassLoader) ctor.newInstance(builtinLoader);
  1971             } catch (Exception e) {
  1972             } catch (Exception e) {
  1972                 throw new Error(e);
  1973                 Throwable cause = e;
       
  1974                 if (e instanceof InvocationTargetException) {
       
  1975                     cause = e.getCause();
       
  1976                     if (cause instanceof Error) {
       
  1977                         throw (Error) cause;
       
  1978                     }
       
  1979                 }
       
  1980                 if (cause instanceof RuntimeException) {
       
  1981                     throw (RuntimeException) cause;
       
  1982                 }
       
  1983                 throw new Error(cause.getMessage(), cause);
  1973             }
  1984             }
  1974         } else {
  1985         } else {
  1975             scl = builtinLoader;
  1986             scl = builtinLoader;
  1976         }
  1987         }
  1977         return scl;
  1988         return scl;