You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/08/01 14:30:22 UTC
[groovy] 01/03: [GROOVY-9109] GroovyShell: don't override
classloader if parent is already GroovyClassLoader
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...@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();
}