groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Create classloader inside doPrivileged block
Date Mon, 04 Dec 2017 12:06:49 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 9ea1eea52 -> a0d7f5334


Create classloader inside doPrivileged block

(cherry picked from commit 3aa0b7e)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a0d7f533
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a0d7f533
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a0d7f533

Branch: refs/heads/GROOVY_2_5_X
Commit: a0d7f53344bb51a20edb8055ce8dacbc6de1b33b
Parents: 9ea1eea
Author: sunlan <sunlan@apache.org>
Authored: Mon Dec 4 20:04:40 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Mon Dec 4 20:06:44 2017 +0800

----------------------------------------------------------------------
 src/main/groovy/util/GroovyScriptEngine.java    | 25 +++++++++++---------
 .../codehaus/groovy/reflection/ClassInfo.java   |  8 ++++++-
 .../codehaus/groovy/tools/GroovyStarter.java    | 10 ++++++--
 3 files changed, 29 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a0d7f533/src/main/groovy/util/GroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/GroovyScriptEngine.java b/src/main/groovy/util/GroovyScriptEngine.java
index aecb27a..7b5ad50 100644
--- a/src/main/groovy/util/GroovyScriptEngine.java
+++ b/src/main/groovy/util/GroovyScriptEngine.java
@@ -69,9 +69,12 @@ import java.util.concurrent.ConcurrentHashMap;
  * @author Mattias Reichel
  */
 public class GroovyScriptEngine implements ResourceConnector {
+    private static final ClassLoader CL_STUB = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+        public ClassLoader run() {
+            return new ClassLoader() {};
+        }
+    });
 
-    private static final ClassLoader CL_STUB = new ClassLoader() {
-    };
     private static final URL[] EMPTY_URL_ARRAY = new URL[0];
 
     private static class LocalData {
@@ -366,15 +369,15 @@ public class GroovyScriptEngine implements ResourceConnector {
      */
     private GroovyClassLoader initGroovyLoader() {
         GroovyClassLoader groovyClassLoader =
-            (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                if (parentLoader instanceof GroovyClassLoader) {
-                    return new ScriptClassLoader((GroovyClassLoader) parentLoader);
-                } else {
-                    return new ScriptClassLoader(parentLoader, config);
-                }
-            }
-        });
+                AccessController.doPrivileged(new PrivilegedAction<ScriptClassLoader>()
{
+                    public ScriptClassLoader run() {
+                        if (parentLoader instanceof GroovyClassLoader) {
+                            return new ScriptClassLoader((GroovyClassLoader) parentLoader);
+                        } else {
+                            return new ScriptClassLoader(parentLoader, config);
+                        }
+                    }
+                });
         for (URL root : roots) groovyClassLoader.addURL(root);
         return groovyClassLoader;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/a0d7f533/src/main/org/codehaus/groovy/reflection/ClassInfo.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/ClassInfo.java b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
index 49c5743..b4dc133 100644
--- a/src/main/org/codehaus/groovy/reflection/ClassInfo.java
+++ b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
@@ -54,6 +54,8 @@ import org.codehaus.groovy.vmplugin.VMPluginFactory;
 import java.lang.ref.WeakReference;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -460,7 +462,11 @@ public class ClassInfo implements Finalizable {
         }
 
         public ClassLoaderForClassArtifacts initValue() {
-            return new ClassLoaderForClassArtifacts(info.classRef.get());
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoaderForClassArtifacts>()
{
+                public ClassLoaderForClassArtifacts run() {
+                    return new ClassLoaderForClassArtifacts(info.classRef.get());
+                }
+            });
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/a0d7f533/src/main/org/codehaus/groovy/tools/GroovyStarter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/GroovyStarter.java b/src/main/org/codehaus/groovy/tools/GroovyStarter.java
index a8164db..d4799f4 100644
--- a/src/main/org/codehaus/groovy/tools/GroovyStarter.java
+++ b/src/main/org/codehaus/groovy/tools/GroovyStarter.java
@@ -21,6 +21,8 @@ package org.codehaus.groovy.tools;
 import java.io.FileInputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 /**
  * Helper class to initialize the Groovy runtime.
@@ -35,7 +37,7 @@ public class GroovyStarter {
     
     public static void rootLoader(String args[]) {
         String conf = System.getProperty("groovy.starter.conf",null);
-        LoaderConfiguration lc = new LoaderConfiguration();
+        final LoaderConfiguration lc = new LoaderConfiguration();
         
         // evaluate parameters
         boolean hadMain=false, hadConf=false, hadCP=false;
@@ -92,7 +94,11 @@ public class GroovyStarter {
             }
         }
         // create loader and execute main class
-        ClassLoader loader = new RootLoader(lc);
+        ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<RootLoader>()
{
+            public RootLoader run() {
+                return new RootLoader(lc);
+            }
+        });
         Method m=null;
         try {
             Class c = loader.loadClass(lc.getMainClass());


Mime
View raw message