< prev index next >
src/java.base/share/classes/java/lang/ClassLoader.java
Print this page
*** 28,37 ****
--- 28,38 ----
import java.io.InputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.File;
import java.lang.reflect.Constructor;
+ import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.CodeSource;
import java.security.PrivilegedAction;
*** 1865,1875 ****
* instance is then created using this constructor with the default system
* class loader as the parameter. The resulting class loader is defined
* to be the system class loader. During construction, the class loader
* should take great care to avoid calling {@code getSystemClassLoader()}.
* If circular initialization of the system class loader is detected then
! * an unspecified error or exception is thrown.
*
* @implNote The system property to override the system class loader is not
* examined until the VM is almost fully initialized. Code that executes
* this method during startup should take care not to cache the return
* value until the system is fully initialized.
--- 1866,1876 ----
* instance is then created using this constructor with the default system
* class loader as the parameter. The resulting class loader is defined
* to be the system class loader. During construction, the class loader
* should take great care to avoid calling {@code getSystemClassLoader()}.
* If circular initialization of the system class loader is detected then
! * an {@code IllegalStateException} is thrown.
*
* @implNote The system property to override the system class loader is not
* examined until the VM is almost fully initialized. Code that executes
* this method during startup should take care not to cache the return
* value until the system is fully initialized.
*** 1916,1927 ****
case 1:
case 2:
// the system class loader is the built-in app class loader during startup
return getBuiltinAppClassLoader();
case 3:
! String msg = "getSystemClassLoader should only be called after VM booted";
! throw new InternalError(msg);
case 4:
// system fully initialized
assert VM.isBooted() && scl != null;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
--- 1917,1928 ----
case 1:
case 2:
// the system class loader is the built-in app class loader during startup
return getBuiltinAppClassLoader();
case 3:
! String msg = "getSystemClassLoader cannot be called during the system class loader instantiation";
! throw new IllegalStateException(msg);
case 4:
// system fully initialized
assert VM.isBooted() && scl != null;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
*** 1967,1977 ****
// custom class loader is only supported to be loaded from unnamed module
Constructor<?> ctor = Class.forName(cn, false, builtinLoader)
.getDeclaredConstructor(ClassLoader.class);
scl = (ClassLoader) ctor.newInstance(builtinLoader);
} catch (Exception e) {
! throw new Error(e);
}
} else {
scl = builtinLoader;
}
return scl;
--- 1968,1985 ----
// custom class loader is only supported to be loaded from unnamed module
Constructor<?> ctor = Class.forName(cn, false, builtinLoader)
.getDeclaredConstructor(ClassLoader.class);
scl = (ClassLoader) ctor.newInstance(builtinLoader);
} catch (Exception e) {
! Throwable cause = e;
! if (e instanceof InvocationTargetException) {
! cause = e.getCause();
! if (cause instanceof RuntimeException) {
! throw (RuntimeException) cause;
! }
! }
! throw new Error(cause.getMessage(), cause);
}
} else {
scl = builtinLoader;
}
return scl;
< prev index next >