commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1211674 - in /commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder: BinderClassLoader.java DigesterLoader.java
Date Wed, 07 Dec 2011 22:18:29 GMT
Author: simonetripodi
Date: Wed Dec  7 22:18:29 2011
New Revision: 1211674

URL: http://svn.apache.org/viewvc?rev=1211674&view=rev
Log:
fixed findbugs issue: classloader must be created inside a privileged action

Modified:
    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java

Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java?rev=1211674&r1=1211673&r2=1211674&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
(original)
+++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
Wed Dec  7 22:18:29 2011
@@ -1,9 +1,5 @@
 package org.apache.commons.digester3.binder;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -23,6 +19,14 @@ import java.util.Map;
  * under the License.
  */
 
+import static java.lang.System.getSecurityManager;
+import static java.security.AccessController.doPrivileged;
+
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
 final class BinderClassLoader
     extends ClassLoader
 {
@@ -42,9 +46,28 @@ final class BinderClassLoader
         PRIMITIVE_TYPES = Collections.unmodifiableMap( primitiveTypes );
     }
 
+    public static BinderClassLoader createBinderClassLoader( final ClassLoader adaptedClassLoader
)
+    {
+        PrivilegedAction<BinderClassLoader> action = new PrivilegedAction<BinderClassLoader>()
+        {
+
+            public BinderClassLoader run()
+            {
+                return new BinderClassLoader( adaptedClassLoader );
+            }
+
+        };
+
+        if ( getSecurityManager() != null )
+        {
+            return doPrivileged( action );
+        }
+        return action.run();
+    }
+
     private final ClassLoader adaptedClassLoader;
 
-    public BinderClassLoader( ClassLoader adaptedClassLoader )
+    private BinderClassLoader( ClassLoader adaptedClassLoader )
     {
         this.adaptedClassLoader = adaptedClassLoader;
     }

Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java?rev=1211674&r1=1211673&r2=1211674&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
(original)
+++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
Wed Dec  7 22:18:29 2011
@@ -19,6 +19,8 @@ package org.apache.commons.digester3.bin
  * under the License.
  */
 
+import static org.apache.commons.digester3.binder.BinderClassLoader.createBinderClassLoader;
+
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.MalformedURLException;
@@ -196,7 +198,7 @@ public final class DigesterLoader
             throw new IllegalArgumentException( "Parameter 'classLoader' cannot be null"
);
         }
 
-        this.classLoader = new BinderClassLoader( classLoader );
+        this.classLoader = createBinderClassLoader( classLoader );
         return this;
     }
 



Mime
View raw message