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 2021/10/05 14:19:51 UTC

[groovy] 01/01: Try to address "java.security.AccessControlException: suppressAccessChecks"

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

sunlan pushed a commit to branch danielsun/GROOVY-10281
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 9f05bbf191e249c0ca29b5cf23cff86ca46d1faf
Author: Daniel Sun <su...@apache.org>
AuthorDate: Tue Oct 5 22:19:27 2021 +0800

    Try to address "java.security.AccessControlException: suppressAccessChecks"
---
 .../groovy/control/CompilerConfiguration.java      | 78 +++-------------------
 src/test/groovy/bugs/Groovy10281.groovy            | 62 -----------------
 2 files changed, 8 insertions(+), 132 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index ae5b2c7..760b9d6 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -40,7 +40,6 @@ import java.util.Set;
 import java.util.StringTokenizer;
 
 import static org.apache.groovy.util.SystemUtil.getBooleanSafe;
-import static org.apache.groovy.util.SystemUtil.getIntegerSafe;
 import static org.apache.groovy.util.SystemUtil.getSystemPropertySafe;
 import static org.codehaus.groovy.runtime.StringGroovyMethods.isAtLeast;
 
@@ -402,16 +401,6 @@ public class CompilerConfiguration {
     private boolean sealedAnnotations;
 
     /**
-     * Whether logging class generation is enabled
-     */
-    private boolean logClassgen;
-
-    /**
-     * sets logging class generation stack trace max depth
-     */
-    private int logClassgenStackTraceMaxDepth;
-
-    /**
      * options for joint compilation (null by default == no joint compilation)
      */
     private Map<String, Object> jointCompilationOptions;
@@ -432,7 +421,6 @@ public class CompilerConfiguration {
 
     private BytecodeProcessor bytecodePostprocessor;
 
-
     /**
      * Sets the compiler flags/settings to default values.
      *
@@ -474,8 +462,6 @@ public class CompilerConfiguration {
         recordsNative = !getBooleanSafe("groovy.records.native.disable");
         sealedNative = !getBooleanSafe("groovy.sealed.native.disable");
         sealedAnnotations = !getBooleanSafe("groovy.sealed.annotations.disable");
-        logClassgen = getBooleanSafe("groovy.log.classgen");
-        logClassgenStackTraceMaxDepth = getIntegerSafe("groovy.log.classgen.stacktrace.max.depth", 0);
         sourceEncoding = getSystemPropertySafe("groovy.source.encoding",
                 getSystemPropertySafe("file.encoding", DEFAULT_SOURCE_ENCODING));
         setTargetDirectorySafe(getSystemPropertySafe("groovy.target.directory"));
@@ -524,8 +510,6 @@ public class CompilerConfiguration {
         setPreviewFeatures(configuration.isPreviewFeatures());
         setSealedNative(configuration.isSealedNative());
         setSealedAnnotations(configuration.isSealedAnnotations());
-        setLogClassgen(configuration.isLogClassgen());
-        setLogClassgenStackTraceMaxDepth(configuration.getLogClassgenStackTraceMaxDepth());
         setDefaultScriptExtension(configuration.getDefaultScriptExtension());
         setSourceEncoding(configuration.getSourceEncoding());
         Map<String, Object> jointCompilationOptions = configuration.getJointCompilationOptions();
@@ -693,19 +677,6 @@ public class CompilerConfiguration {
         text = configuration.getProperty("groovy.sealed.annotations.disable");
         if (text != null) setSealedAnnotations(!text.equalsIgnoreCase("false"));
 
-        text = configuration.getProperty("groovy.log.classgen");
-        if (text != null) setLogClassgen(text.equalsIgnoreCase("true"));
-
-        text = configuration.getProperty("groovy.log.classgen.stacktrace.max.depth");
-        if (text != null) {
-            int logClassgenStackTraceMaxDepth = 0;
-            try {
-                logClassgenStackTraceMaxDepth = Integer.parseInt(text);
-            } catch (Exception ignored) {
-            }
-            setLogClassgenStackTraceMaxDepth(Math.max(logClassgenStackTraceMaxDepth, 0));
-        }
-
         text = configuration.getProperty("groovy.classpath");
         if (text != null) setClasspath(text);
 
@@ -753,7 +724,6 @@ public class CompilerConfiguration {
         }
     }
 
-
     /**
      * Gets the currently configured warning level. See {@link WarningMessage}
      * for level details.
@@ -1089,46 +1059,6 @@ public class CompilerConfiguration {
     }
 
     /**
-     * Returns whether logging class generation is enabled
-     *
-     * @return whether logging class generation is enabled
-     * @since 4.0.0
-     */
-    public boolean isLogClassgen() {
-        return logClassgen;
-    }
-
-    /**
-     * Sets whether logging class generation is enabled
-     *
-     * @param logClassgen whether to enable logging class generation
-     * @since 4.0.0
-     */
-    public void setLogClassgen(boolean logClassgen) {
-        this.logClassgen = logClassgen;
-    }
-
-    /**
-     * Returns stack trace max depth of logging class generation
-     *
-     * @return stack trace max depth of logging class generation
-     * @since 4.0.0
-     */
-    public int getLogClassgenStackTraceMaxDepth() {
-        return logClassgenStackTraceMaxDepth;
-    }
-
-    /**
-     * Sets stack trace max depth of logging class generation
-     *
-     * @param logClassgenStackTraceMaxDepth stack trace max depth of logging class generation
-     * @since 4.0.0
-     */
-    public void setLogClassgenStackTraceMaxDepth(int logClassgenStackTraceMaxDepth) {
-        this.logClassgenStackTraceMaxDepth = logClassgenStackTraceMaxDepth;
-    }
-
-    /**
      * Gets the joint compilation options for this configuration.
      * @return the options
      */
@@ -1243,4 +1173,12 @@ public class CompilerConfiguration {
         Boolean runtimeGroovydocEnabled = getOptimizationOptions().get(RUNTIME_GROOVYDOC);
         return Optional.ofNullable(runtimeGroovydocEnabled).orElse(Boolean.FALSE).booleanValue();
     }
+
+    public boolean isLogClassgen() {
+        return false;
+    }
+
+    public int getLogClassgenStackTraceMaxDepth() {
+        return 0;
+    }
 }
diff --git a/src/test/groovy/bugs/Groovy10281.groovy b/src/test/groovy/bugs/Groovy10281.groovy
deleted file mode 100644
index 4468433..0000000
--- a/src/test/groovy/bugs/Groovy10281.groovy
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package bugs
-
-import groovy.transform.CompileStatic
-import org.codehaus.groovy.control.CompilationUnit
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.control.Phases
-import org.junit.Test
-
-@CompileStatic
-final class Groovy10281 {
-    @Test
-    void testLoggingClassGenWithStacktrace() {
-        def result = logClassGen(true)
-        assert result.contains('// org.codehaus.groovy.classgen.AsmClassGenerator#visitClass:')
-        assert result.contains('public class helloWorld extends groovy/lang/Script {')
-        assert result.contains('LDC "Hello, world!"')
-    }
-
-    @Test
-    void testLoggingClassGenWithoutStacktrace() {
-        def result = logClassGen(false)
-        assert !result.contains('// org.codehaus.groovy.classgen.AsmClassGenerator#visitClass:')
-        assert result.contains('public class helloWorld extends groovy/lang/Script {')
-        assert result.contains('LDC "Hello, world!"')
-    }
-
-    private static String logClassGen(boolean stacktrace) {
-        def code = """
-                println 'Hello, world!'
-            """
-        def result = new StringWriter()
-        PrintWriter pw = new PrintWriter(result)
-        def config = stacktrace ? new CompilerConfiguration(logClassgen: true, logClassgenStackTraceMaxDepth: 50, output: pw)
-                                                    : new CompilerConfiguration(logClassgen: true, output: pw)
-
-        new CompilationUnit(config).with {
-            addSource 'helloWorld.groovy', code
-            compile Phases.CLASS_GENERATION
-        }
-
-        pw.close()
-        return result.toString()
-    }
-}