You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/04/19 10:41:07 UTC

[groovy] branch master updated: avoid the doPriveleged block for the null case

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d001339  avoid the doPriveleged block for the null case
d001339 is described below

commit d0013391bc7a6999045c09f04f6af30c19610c79
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Apr 19 20:40:54 2019 +1000

    avoid the doPriveleged block for the null case
---
 .../codehaus/groovy/control/ProcessingUnit.java    | 24 +++++-----------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
index 66715a4..d230a97 100644
--- a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
@@ -33,6 +33,7 @@ public abstract class ProcessingUnit {
      * The current phase
      */
     protected int phase;
+
     /**
      * Set true if phase is finished
      */
@@ -53,11 +54,9 @@ public abstract class ProcessingUnit {
      */
     protected ErrorCollector errorCollector;
 
-
     /**
      * Initialize the ProcessingUnit to the empty state.
      */
-
     public ProcessingUnit(CompilerConfiguration configuration, GroovyClassLoader classLoader, ErrorCollector er) {
 
         this.phase = Phases.INITIALIZATION;
@@ -68,7 +67,6 @@ public abstract class ProcessingUnit {
         this.errorCollector = er;
     }
 
-
     /**
      * Reconfigures the ProcessingUnit.
      */
@@ -76,7 +74,6 @@ public abstract class ProcessingUnit {
         this.configuration = configuration;
     }
 
-
     public CompilerConfiguration getConfiguration() {
         return configuration;
     }
@@ -88,43 +85,35 @@ public abstract class ProcessingUnit {
     /**
      * Returns the class loader in use by this ProcessingUnit.
      */
-
     public GroovyClassLoader getClassLoader() {
         return classLoader;
     }
 
-
     /**
      * Sets the class loader for use by this ProcessingUnit.
      */
-
     public void setClassLoader(final GroovyClassLoader loader) {
-        // Classloaders should only be created inside doPrivileged block
-        // This code creates a classloader, which needs permission if a security manage is installed.
-        // If this code might be invoked by code that does not have security permissions, then the classloader creation needs to occur inside a doPrivileged block.
-        this.classLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
+        // Classloaders should only be created inside a doPrivileged block in case
+        // this method is invoked by code that does not have security permissions
+        this.classLoader = loader != null ? loader : AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
             public GroovyClassLoader run() {
                 ClassLoader parent = Thread.currentThread().getContextClassLoader();
                 if (parent == null) parent = ProcessingUnit.class.getClassLoader();
-                return loader == null ? new GroovyClassLoader(parent, configuration) : loader;
+                return new GroovyClassLoader(parent, configuration);
             }
         });
     }
 
-
     /**
      * Returns the current phase.
      */
-
     public int getPhase() {
         return this.phase;
     }
 
-
     /**
      * Returns the description for the current phase.
      */
-
     public String getPhaseDescription() {
         return Phases.getDescription(this.phase);
     }
@@ -146,13 +135,11 @@ public abstract class ProcessingUnit {
      * Marks the current phase complete and processes any
      * errors.
      */
-
     public void completePhase() throws CompilationFailedException {
         errorCollector.failIfErrors();
         phaseComplete = true;
     }
 
-
     /**
      * A synonym for <code>gotoPhase( phase + 1 )</code>.
      */
@@ -160,7 +147,6 @@ public abstract class ProcessingUnit {
         gotoPhase(this.phase + 1);
     }
 
-
     /**
      * Wraps up any pending operations for the current phase
      * and switches to the next phase.