You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2018/04/27 16:32:38 UTC

[GitHub] dkulp closed pull request #413: no need of instantiating so much objects when security manager is null

dkulp closed pull request #413: no need of instantiating so much objects when security manager is null
URL: https://github.com/apache/cxf/pull/413
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/org/apache/cxf/common/classloader/ClassLoaderUtils.java b/core/src/main/java/org/apache/cxf/common/classloader/ClassLoaderUtils.java
index ce395166650..d90dc4dec0d 100644
--- a/core/src/main/java/org/apache/cxf/common/classloader/ClassLoaderUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/classloader/ClassLoaderUtils.java
@@ -36,26 +36,46 @@
  * verify any change on 6 different application servers.
  */
 public final class ClassLoaderUtils {
+    private static final boolean SKIP_SM = System.getSecurityManager() == null;
 
     private ClassLoaderUtils() {
     }
 
     public static class ClassLoaderHolder {
         ClassLoader loader;
-        ClassLoaderHolder(ClassLoader c) {
-            loader = c;
+        Thread thread;
+
+        ClassLoaderHolder(final ClassLoader c, final Thread thread) {
+            this.loader = c;
+            this.thread = thread;
         }
 
         public void reset() {
-            ClassLoaderUtils.setThreadContextClassloader(loader);
+            if (SKIP_SM) {
+                thread.setContextClassLoader(loader);
+            } else {
+                AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                    public Void run() {
+                        thread.setContextClassLoader(loader);
+                        return null;
+                    }
+                });
+            }
         }
     }
     public static ClassLoaderHolder setThreadContextClassloader(final ClassLoader newLoader) {
+        if (SKIP_SM) {
+            final Thread thread = Thread.currentThread();
+            final ClassLoader l = thread.getContextClassLoader();
+            thread.setContextClassLoader(newLoader);
+            return new ClassLoaderHolder(l, thread);
+        }
         return AccessController.doPrivileged(new PrivilegedAction<ClassLoaderHolder>() {
             public ClassLoaderHolder run() {
-                ClassLoader l = Thread.currentThread().getContextClassLoader();
-                Thread.currentThread().setContextClassLoader(newLoader);
-                return new ClassLoaderHolder(l);
+                final Thread thread = Thread.currentThread();
+                final ClassLoader l = thread.getContextClassLoader();
+                thread.setContextClassLoader(newLoader);
+                return new ClassLoaderHolder(l, thread);
             }
         });
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services