summaryrefslogtreecommitdiff
path: root/external/ikvm/openjdk/java/lang/ClassLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'external/ikvm/openjdk/java/lang/ClassLoader.java')
-rw-r--r--external/ikvm/openjdk/java/lang/ClassLoader.java57
1 files changed, 39 insertions, 18 deletions
diff --git a/external/ikvm/openjdk/java/lang/ClassLoader.java b/external/ikvm/openjdk/java/lang/ClassLoader.java
index 8162ba81c0..57c1ee3e39 100644
--- a/external/ikvm/openjdk/java/lang/ClassLoader.java
+++ b/external/ikvm/openjdk/java/lang/ClassLoader.java
@@ -56,6 +56,7 @@ import sun.misc.CompoundEnumeration;
import sun.misc.Resource;
import sun.misc.URLClassPath;
import sun.misc.VM;
+import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import sun.security.util.SecurityConstants;
@@ -1256,9 +1257,11 @@ public abstract class ClassLoader {
*
* @since 1.7
*/
- @ikvm.internal.HasCallerID
+ @CallerSensitive
protected static boolean registerAsParallelCapable() {
- return ParallelLoaders.register(ikvm.internal.CallerID.getCallerID().getCallerClass());
+ Class<? extends ClassLoader> callerClass =
+ Reflection.getCallerClass().asSubclass(ClassLoader.class);
+ return ParallelLoaders.register(callerClass);
}
/**
@@ -1402,15 +1405,13 @@ public abstract class ClassLoader {
*
* @since 1.2
*/
+ @CallerSensitive
public final ClassLoader getParent() {
if (parent == null)
return null;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- ClassLoader ccl = getCallerClassLoader();
- if (ccl != null && !isAncestor(ccl)) {
- sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
- }
+ checkClassLoaderPermission(parent, Reflection.getCallerClass());
}
return parent;
}
@@ -1470,7 +1471,7 @@ public abstract class ClassLoader {
*
* @revised 1.4
*/
- @ikvm.internal.HasCallerID
+ @CallerSensitive
public static ClassLoader getSystemClassLoader() {
initSystemClassLoader();
if (scl == null) {
@@ -1478,10 +1479,7 @@ public abstract class ClassLoader {
}
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- ClassLoader ccl = getCallerClassLoader();
- if (ccl != null && ccl != scl && !scl.isAncestor(ccl)) {
- sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
- }
+ checkClassLoaderPermission(scl, Reflection.getCallerClass());
}
return scl;
}
@@ -1529,13 +1527,25 @@ public abstract class ClassLoader {
return false;
}
- // Returns the invoker's class loader, or null if none.
- // NOTE: This must always be invoked when there is exactly one intervening
- // frame from the core libraries on the stack between this method's
- // invocation and the desired invoker.
- static ClassLoader getCallerClassLoader() {
- // NOTE use of more generic Reflection.getCallerClass()
- Class caller = Reflection.getCallerClass(3);
+ // Tests if class loader access requires "getClassLoader" permission
+ // check. A class loader 'from' can access class loader 'to' if
+ // class loader 'from' is same as class loader 'to' or an ancestor
+ // of 'to'. The class loader in a system domain can access
+ // any class loader.
+ private static boolean needsClassLoaderPermissionCheck(ClassLoader from,
+ ClassLoader to)
+ {
+ if (from == to)
+ return false;
+
+ if (from == null)
+ return false;
+
+ return !to.isAncestor(from);
+ }
+
+ // Returns the class's class loader, or null if none.
+ static ClassLoader getClassLoader(Class<?> caller) {
// This can be null if the VM is requesting it
if (caller == null) {
return null;
@@ -1544,6 +1554,17 @@ public abstract class ClassLoader {
return caller.getClassLoader0();
}
+ static void checkClassLoaderPermission(ClassLoader cl, Class<?> caller) {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ // caller can be null if the VM is requesting it
+ ClassLoader ccl = getClassLoader(caller);
+ if (needsClassLoaderPermissionCheck(ccl, cl)) {
+ sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
+ }
+ }
+ }
+
// The class loader for the system
// @GuardedBy("ClassLoader.class")
private static ClassLoader scl;