groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/03: [GROOVY-9109] GroovyShell: don't override classloader if parent is already GroovyClassLoader
Date Thu, 01 Aug 2019 14:30:22 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit da5120febb1860cfa98938d18905b5af7c6be599
Author: Jan Lukavsky <je.ik@seznam.cz>
AuthorDate: Tue Feb 26 23:14:43 2019 +0100

    [GROOVY-9109] GroovyShell: don't override classloader if parent is already GroovyClassLoader
    
    (cherry picked from commit 65c204f57f404205996af4809039c2601774c8e5)
---
 src/main/groovy/groovy/lang/GroovyShell.java | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index 7877037..ad109f5 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -86,7 +86,7 @@ public class GroovyShell extends GroovyObjectSupport {
     public GroovyShell(ClassLoader parent) {
         this(parent, new Binding(), CompilerConfiguration.DEFAULT);
     }
-    
+
     public GroovyShell(ClassLoader parent, Binding binding, final CompilerConfiguration config)
{
         if (binding == null) {
             throw new IllegalArgumentException("Binding must not be null.");
@@ -95,15 +95,19 @@ public class GroovyShell extends GroovyObjectSupport {
             throw new IllegalArgumentException("Compiler configuration must not be null.");
         }
         final ClassLoader parentLoader = (parent!=null)?parent:GroovyShell.class.getClassLoader();
-        this.loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>()
{
-            public GroovyClassLoader run() {
-                return new GroovyClassLoader(parentLoader,config);
-            }
-        });
-        this.context = binding;        
+        if (parentLoader instanceof GroovyClassLoader) {
+          this.loader = (GroovyClassLoader) parentLoader;
+        } else {
+          this.loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>()
{
+              public GroovyClassLoader run() {
+                  return new GroovyClassLoader(parentLoader,config);
+              }
+          });
+        }
+        this.context = binding;
         this.config = config;
     }
-    
+
     public void resetLoadedClasses() {
         loader.clearCache();
     }


Mime
View raw message