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/12/14 14:44:38 UTC

[groovy] 01/03: Revert "Remove deprecated methods of `GroovyClassLoader`"

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

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

commit 3d3ee0f115a995edee2b573305a7d8b634e5a5d6
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Dec 14 22:43:02 2019 +0800

    Revert "Remove deprecated methods of `GroovyClassLoader`"
    
    We should not introduce any breaking changes in the RC phase. The commit was merged by accident
---
 src/main/java/groovy/lang/GroovyClassLoader.java | 28 ++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java b/src/main/java/groovy/lang/GroovyClassLoader.java
index 27e7038..abc6da0 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -288,6 +288,28 @@ 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
+     */
+    @Deprecated
+    public Class parseClass(final InputStream in, final String fileName) throws CompilationFailedException {
+        // For generic input streams, provide a catch-all codebase of GroovyScript
+        // Security for these classes can be administered via policy grants with
+        // a codebase of file:groovy.script
+        GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> {
+            try {
+                String scriptText = config.getSourceEncoding() != null ?
+                        IOGroovyMethods.getText(in, config.getSourceEncoding()) :
+                        IOGroovyMethods.getText(in);
+                return new GroovyCodeSource(scriptText, fileName, "/groovy/script");
+            } catch (IOException e) {
+                throw new RuntimeException("Impossible to read the content of the input stream for file named: " + fileName, e);
+            }
+        });
+        return parseClass(gcs);
+    }
+
     public Class parseClass(GroovyCodeSource codeSource) throws CompilationFailedException {
         return parseClass(codeSource, codeSource.isCachable());
     }
@@ -550,6 +572,12 @@ public class GroovyClassLoader extends URLClassLoader {
         }
 
         @Override
+        @Deprecated
+        public Class parseClass(InputStream in, String fileName) throws CompilationFailedException {
+            return delegate.parseClass(in, fileName);
+        }
+
+        @Override
         public Class parseClass(GroovyCodeSource codeSource) throws CompilationFailedException {
             return delegate.parseClass(codeSource);
         }