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:21 UTC

[groovy] branch GROOVY_2_5_X updated (d53325e -> d5c3474)

This is an automated email from the ASF dual-hosted git repository.

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


    from d53325e  GROOVY-9202: Bump picocli to 4.0.1 (fix jarjar processing)
     new da5120f  [GROOVY-9109] GroovyShell: don't override classloader if parent is already GroovyClassLoader
     new 0e14fb8  [GROOVY-9109] override the classloader with different config
     new d5c3474  [GROOVY-9109] Don't leak CompilerConfiguration from GroovyClassLoader

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/groovy/groovy/lang/GroovyClassLoader.java | 15 +++++++++++++--
 src/main/groovy/groovy/lang/GroovyShell.java       | 22 ++++++++++++++--------
 2 files changed, 27 insertions(+), 10 deletions(-)


[groovy] 03/03: [GROOVY-9109] Don't leak CompilerConfiguration from GroovyClassLoader

Posted by su...@apache.org.
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>() {


[groovy] 01/03: [GROOVY-9109] GroovyShell: don't override classloader if parent is already GroovyClassLoader

Posted by su...@apache.org.
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();
     }


[groovy] 02/03: [GROOVY-9109] override the classloader with different config

Posted by su...@apache.org.
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 0e14fb8af9fcbafc0902a31520257220bc948b2a
Author: Jan Lukavsky <je...@seznam.cz>
AuthorDate: Thu May 23 14:25:15 2019 +0200

    [GROOVY-9109] override the classloader with different config
    
    (cherry picked from commit 9ce87bc821e67a9a60300b88c62a0bed33219134)
---
 src/main/groovy/groovy/lang/GroovyClassLoader.java | 12 ++++++++++--
 src/main/groovy/groovy/lang/GroovyShell.java       |  4 +++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/main/groovy/groovy/lang/GroovyClassLoader.java b/src/main/groovy/groovy/lang/GroovyClassLoader.java
index 6c440f9..0b31298 100644
--- a/src/main/groovy/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/groovy/lang/GroovyClassLoader.java
@@ -225,6 +225,14 @@ public class GroovyClassLoader extends URLClassLoader {
     }
 
     /**
+     * Retrieve configuration used by this class loader.
+     * @return CompilerConfiguration used by this classloader
+     */
+    public CompilerConfiguration getCompilerConfiguration() {
+      return config;
+    }
+
+    /**
      * Parses the given file into a Java class capable of being run
      *
      * @param file the file name to parse
@@ -280,7 +288,7 @@ public class GroovyClassLoader extends URLClassLoader {
         });
         return parseClass(gcs);
     }
-    
+
     /**
      * @deprecated Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
      * Use {@link #parseClass(Reader, String) parseClass} instead
@@ -922,7 +930,7 @@ public class GroovyClassLoader extends URLClassLoader {
     private static File fileReallyExists(URL ret, String fileWithoutPackage) {
         File path;
         try {
-            /* fix for GROOVY-5809 */ 
+            /* fix for GROOVY-5809 */
             path = new File(ret.toURI());
         } catch(URISyntaxException e) {
             path = new File(decodeFileName(ret.getFile()));
diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index ad109f5..cc947ab 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -95,7 +95,9 @@ public class GroovyShell extends GroovyObjectSupport {
             throw new IllegalArgumentException("Compiler configuration must not be null.");
         }
         final ClassLoader parentLoader = (parent!=null)?parent:GroovyShell.class.getClassLoader();
-        if (parentLoader instanceof GroovyClassLoader) {
+
+        if (parentLoader instanceof GroovyClassLoader
+            && ((GroovyClassLoader) parentLoader).getCompilerConfiguration() == config) {
           this.loader = (GroovyClassLoader) parentLoader;
         } else {
           this.loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {