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/07/31 23:16:46 UTC

[groovy] branch master updated (faa80fd -> 390af08)

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

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


    from faa80fd  GROOVY-9208: Adapt the groovysh with the new parser Parrot (closes #983)
     new 65c204f  [GROOVY-9109] GroovyShell: don't override classloader if parent is already GroovyClassLoader
     new 9ce87bc  [GROOVY-9109] override the classloader with different config
     new 390af08  [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/java/groovy/lang/GroovyClassLoader.java | 15 +++++++++++++--
 src/main/java/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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 390af080a7ea4b1d3c470ed8e3338fe9c6c7c613
Author: Jan Lukavsky <je...@seznam.cz>
AuthorDate: Mon May 27 11:21:58 2019 +0200

    [GROOVY-9109] Don't leak CompilerConfiguration from GroovyClassLoader
---
 src/main/java/groovy/lang/GroovyClassLoader.java | 11 +++++++----
 src/main/java/groovy/lang/GroovyShell.java       |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java b/src/main/java/groovy/lang/GroovyClassLoader.java
index 1eb80d3..262b232 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/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/java/groovy/lang/GroovyShell.java b/src/main/java/groovy/lang/GroovyShell.java
index 956ed49..6f32a3c 100644
--- a/src/main/java/groovy/lang/GroovyShell.java
+++ b/src/main/java/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] 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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 9ce87bc821e67a9a60300b88c62a0bed33219134
Author: Jan Lukavsky <je...@seznam.cz>
AuthorDate: Thu May 23 14:25:15 2019 +0200

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

diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java b/src/main/java/groovy/lang/GroovyClassLoader.java
index ac3b75f..1eb80d3 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/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
@@ -1031,7 +1039,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/java/groovy/lang/GroovyShell.java b/src/main/java/groovy/lang/GroovyShell.java
index e326959..956ed49 100644
--- a/src/main/java/groovy/lang/GroovyShell.java
+++ b/src/main/java/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>() {


[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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 65c204f57f404205996af4809039c2601774c8e5
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
---
 src/main/java/groovy/lang/GroovyShell.java | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/main/java/groovy/lang/GroovyShell.java b/src/main/java/groovy/lang/GroovyShell.java
index b0adb01..e326959 100644
--- a/src/main/java/groovy/lang/GroovyShell.java
+++ b/src/main/java/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();
     }