changeset 7442:4934254492af

8006611: Improve scripting Reviewed-by: mchung
author sundar
date Fri, 19 Apr 2013 11:43:19 +0100
parents cf14f699f36c
children a73ecb5085eb
files src/share/classes/javax/script/ScriptEngineManager.java
diffstat 1 files changed, 2 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/script/ScriptEngineManager.java	Thu Apr 18 13:52:38 2013 +0100
+++ b/src/share/classes/javax/script/ScriptEngineManager.java	Fri Apr 19 11:43:19 2013 +0100
@@ -28,9 +28,6 @@
 import java.security.*;
 import java.util.ServiceLoader;
 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
@@ -54,23 +51,14 @@
 public class ScriptEngineManager  {
     private static final boolean DEBUG = false;
     /**
-     * If the thread context ClassLoader can be accessed by the caller,
-     * then the effect of calling this constructor is the same as calling
+     * The effect of calling this constructor is the same as calling
      * <code>ScriptEngineManager(Thread.currentThread().getContextClassLoader())</code>.
-     * Otherwise, the effect is the same as calling <code>ScriptEngineManager(null)</code>.
      *
      * @see java.lang.Thread#getContextClassLoader
      */
-    @CallerSensitive
     public ScriptEngineManager() {
         ClassLoader ctxtLoader = Thread.currentThread().getContextClassLoader();
-        if (canCallerAccessLoader(ctxtLoader, Reflection.getCallerClass())) {
-            if (DEBUG) System.out.println("using " + ctxtLoader);
-            init(ctxtLoader);
-        } else {
-            if (DEBUG) System.out.println("using bootstrap loader");
-            init(null);
-        }
+        init(ctxtLoader);
     }
 
     /**
@@ -420,41 +408,4 @@
 
     /** Global bindings associated with script engines created by this manager. */
     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;
-    }
 }