145 |
* is somewhat circular - getSystemClassLoader() checks whether this |
* is somewhat circular - getSystemClassLoader() checks whether this |
146 |
* field is null in order to bypass a security check. |
* field is null in order to bypass a security check. |
147 |
*/ |
*/ |
148 |
static final ClassLoader systemClassLoader = getSystemClassLoader(); |
static final ClassLoader systemClassLoader = VMClassLoader.getSystemClassLoader(); |
149 |
|
|
150 |
/** |
/** |
151 |
* The default protection domain, used when defining a class with a null |
* The default protection domain, used when defining a class with a null |
744 |
*/ |
*/ |
745 |
public static ClassLoader getSystemClassLoader() |
public static ClassLoader getSystemClassLoader() |
746 |
{ |
{ |
747 |
// This method is called as the initialization of systemClassLoader, |
// Check if we may return the system classloader |
748 |
// so if there is a null value, this is the first call and we must check |
SecurityManager sm = System.getSecurityManager(); |
749 |
// for java.system.class.loader. |
if (sm != null) |
750 |
if (systemClassLoader == null) |
{ |
751 |
{ |
Class c = VMSecurityManager.getClassContext()[1]; |
752 |
String loader = System.getProperty("java.system.class.loader", |
ClassLoader cl = c.getClassLoader(); |
753 |
"gnu.java.lang.SystemClassLoader"); |
if (cl != null && cl != systemClassLoader) |
754 |
try |
sm.checkPermission(new RuntimePermission("getClassLoader")); |
755 |
{ |
} |
756 |
// Give the new system class loader a null parent. |
|
757 |
Constructor c = Class.forName(loader).getConstructor |
return systemClassLoader; |
|
( new Class[] { ClassLoader.class } ); |
|
|
return (ClassLoader) c.newInstance(new Object[1]); |
|
|
} |
|
|
catch (Exception e) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
System.err.println("Requested system classloader " |
|
|
+ loader + " failed, trying " |
|
|
+ "gnu.java.lang.SystemClassLoader"); |
|
|
e.printStackTrace(); |
|
|
// Fallback to gnu.java.lang.SystemClassLoader. |
|
|
return new SystemClassLoader(null); |
|
|
} |
|
|
catch (Exception e1) |
|
|
{ |
|
|
throw (Error) new InternalError |
|
|
("System class loader could not be found: " + e1) |
|
|
.initCause(e1); |
|
|
} |
|
|
} |
|
|
} |
|
|
// Check if we may return the system classloader |
|
|
SecurityManager sm = System.getSecurityManager(); |
|
|
if (sm != null) |
|
|
{ |
|
|
Class c = VMSecurityManager.getClassContext()[1]; |
|
|
ClassLoader cl = c.getClassLoader(); |
|
|
if (cl != null && cl != systemClassLoader) |
|
|
sm.checkPermission(new RuntimePermission("getClassLoader")); |
|
|
} |
|
|
return systemClassLoader; |
|
758 |
} |
} |
759 |
|
|
760 |
/** |
/** |