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:24 UTC
[groovy] 03/03: [GROOVY-9109] Don't leak CompilerConfiguration from
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 d5c3474cd6199d6202d06023e5f5ea7066508c18
Author: Jan Lukavsky <je...@seznam.cz>
AuthorDate: Mon May 27 11:21:58 2019 +0200
[GROOVY-9109] Don't leak CompilerConfiguration from GroovyClassLoader
(cherry picked from commit 390af080a7ea4b1d3c470ed8e3338fe9c6c7c613)
---
src/main/groovy/groovy/lang/GroovyClassLoader.java | 11 +++++++----
src/main/groovy/groovy/lang/GroovyShell.java | 2 +-
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/main/groovy/groovy/lang/GroovyClassLoader.java b/src/main/groovy/groovy/lang/GroovyClassLoader.java
index 0b31298..4bdfe38 100644
--- a/src/main/groovy/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/groovy/lang/GroovyClassLoader.java
@@ -225,11 +225,14 @@ public class GroovyClassLoader extends URLClassLoader {
}
/**
- * Retrieve configuration used by this class loader.
- * @return CompilerConfiguration used by this classloader
+ * Check if this class loader has compatible {@link CompilerConfiguration}
+ * with the provided one.
+ * @param config the compiler configuration to test for compatibility
+ * @return {@code true} if the provided config is exactly the same instance
+ * of {@link CompilerConfiguration} as this loader has
*/
- public CompilerConfiguration getCompilerConfiguration() {
- return config;
+ public boolean hasCompatibleConfiguration(CompilerConfiguration config) {
+ return this.config == config;
}
/**
diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index cc947ab..39f29f8 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -97,7 +97,7 @@ public class GroovyShell extends GroovyObjectSupport {
final ClassLoader parentLoader = (parent!=null)?parent:GroovyShell.class.getClassLoader();
if (parentLoader instanceof GroovyClassLoader
- && ((GroovyClassLoader) parentLoader).getCompilerConfiguration() == config) {
+ && ((GroovyClassLoader) parentLoader).hasCompatibleConfiguration(config)) {
this.loader = (GroovyClassLoader) parentLoader;
} else {
this.loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {