提交 5ff1a97e 编写于 作者: S sundar

8006611: Improve scripting

Reviewed-by: mchung
上级 ca970328
...@@ -28,9 +28,6 @@ import java.util.*; ...@@ -28,9 +28,6 @@ import java.util.*;
import java.security.*; import java.security.*;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.ServiceConfigurationError; import java.util.ServiceConfigurationError;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import sun.security.util.SecurityConstants;
/** /**
* The <code>ScriptEngineManager</code> implements a discovery and instantiation * The <code>ScriptEngineManager</code> implements a discovery and instantiation
...@@ -54,23 +51,14 @@ import sun.security.util.SecurityConstants; ...@@ -54,23 +51,14 @@ import sun.security.util.SecurityConstants;
public class ScriptEngineManager { public class ScriptEngineManager {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
/** /**
* If the thread context ClassLoader can be accessed by the caller, * The effect of calling this constructor is the same as calling
* then the effect of calling this constructor is the same as calling
* <code>ScriptEngineManager(Thread.currentThread().getContextClassLoader())</code>. * <code>ScriptEngineManager(Thread.currentThread().getContextClassLoader())</code>.
* Otherwise, the effect is the same as calling <code>ScriptEngineManager(null)</code>.
* *
* @see java.lang.Thread#getContextClassLoader * @see java.lang.Thread#getContextClassLoader
*/ */
@CallerSensitive
public ScriptEngineManager() { public ScriptEngineManager() {
ClassLoader ctxtLoader = Thread.currentThread().getContextClassLoader(); ClassLoader ctxtLoader = Thread.currentThread().getContextClassLoader();
if (canCallerAccessLoader(ctxtLoader, Reflection.getCallerClass())) { init(ctxtLoader);
if (DEBUG) System.out.println("using " + ctxtLoader);
init(ctxtLoader);
} else {
if (DEBUG) System.out.println("using bootstrap loader");
init(null);
}
} }
/** /**
...@@ -420,41 +408,4 @@ public class ScriptEngineManager { ...@@ -420,41 +408,4 @@ public class ScriptEngineManager {
/** Global bindings associated with script engines created by this manager. */ /** Global bindings associated with script engines created by this manager. */
private Bindings globalScope; private Bindings globalScope;
private boolean canCallerAccessLoader(ClassLoader loader, Class<?> caller) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ClassLoader callerLoader = getClassLoader(caller);
if (!sun.misc.VM.isSystemDomainLoader(callerLoader)) {
if (loader != callerLoader || !isAncestor(loader, callerLoader)) {
try {
sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
} catch (SecurityException exp) {
if (DEBUG) exp.printStackTrace();
return false;
}
} // else fallthru..
} // else fallthru..
} // else fallthru..
return true;
}
// Note that this code is same as ClassLoader.getClassLoader().
// But, that method is package private and hence we can't call here.
private ClassLoader getClassLoader(Class<?> caller) {
if (caller == null) {
return null;
}
return caller.getClassLoader();
}
// is cl1 ancestor of cl2?
private boolean isAncestor(ClassLoader cl1, ClassLoader cl2) {
do {
cl2 = cl2.getParent();
if (cl1 == cl2) return true;
} while (cl2 != null);
return false;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册