[jboss-cvs] JBossAS SVN: r70470 - projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 6 06:29:47 EST 2008


Author: adrian at jboss.org
Date: 2008-03-06 06:29:46 -0500 (Thu, 06 Mar 2008)
New Revision: 70470

Modified:
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SecurityActions.java
Log:
Don't throw an error setting the context classloader if the context is not in a state where it has a classloader, e.g. NOT_INSTALLED

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SecurityActions.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SecurityActions.java	2008-03-06 10:18:43 UTC (rev 70469)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SecurityActions.java	2008-03-06 11:29:46 UTC (rev 70470)
@@ -23,11 +23,10 @@
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
 
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+import org.jboss.logging.Logger;
 
 /**
  * SecurityActions.
@@ -37,51 +36,48 @@
  */
 class SecurityActions
 {
-   static ClassLoader setContextClassLoader(final ControllerContext context) throws Throwable
+   /** The logger */
+   private static final Logger log = Logger.getLogger(SecurityActions.class); 
+   
+   private static ClassLoader setContextClassLoaderInternal(final ControllerContext context)
    {
-      if (System.getSecurityManager() == null)
+      ClassLoader result = Thread.currentThread().getContextClassLoader();
+      if (context instanceof InvokeDispatchContext)
       {
-         ClassLoader result = Thread.currentThread().getContextClassLoader();
-         if (context instanceof InvokeDispatchContext)
-            Thread.currentThread().setContextClassLoader(((InvokeDispatchContext) context).getClassLoader());
-         return result;
-      }
-      else
-      {
+         ClassLoader cl = null;
+         InvokeDispatchContext invokeContext = (InvokeDispatchContext) context;
          try
          {
-            return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
-            {
-                public ClassLoader run() throws Exception
-                {
-                   try
-                   {
-                      ClassLoader result = Thread.currentThread().getContextClassLoader();
-                      if (context instanceof InvokeDispatchContext)
-                         Thread.currentThread().setContextClassLoader(((InvokeDispatchContext) context).getClassLoader());
-                      return result;
-                   }
-                   catch (Exception e)
-                   {
-                      throw e;
-                   }
-                   catch (Error e)
-                   {
-                      throw e;
-                   }
-                   catch (Throwable e)
-                   {
-                      throw new RuntimeException("Error setting context classloader", e);
-                   }
-                }
-            });
+            cl = invokeContext.getClassLoader();
          }
-         catch (PrivilegedActionException e)
+         catch (Throwable t)
          {
-            throw e.getCause();
+            if (log.isTraceEnabled())
+               log.trace("Not setting classloader for " + context.getName() + " reason:" + context);
          }
+         if (cl != null)
+            Thread.currentThread().setContextClassLoader(cl);
       }
+      return result;
    }
+   
+   static ClassLoader setContextClassLoader(final ControllerContext context)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return setContextClassLoaderInternal(context);
+      }
+      else
+      {
+         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+         {
+             public ClassLoader run()
+             {
+                return setContextClassLoaderInternal(context);
+             }
+         });
+      }
+   }
 
    static void resetContextClassLoader(final ClassLoader classLoader)
    {




More information about the jboss-cvs-commits mailing list