[jboss-svn-commits] JBoss Common SVN: r3621 - common-logging-log4j/trunk/src/main/java/org/jboss/logging/filter.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 22 11:56:48 EDT 2009


Author: jaikiran
Date: 2009-10-22 11:56:48 -0400 (Thu, 22 Oct 2009)
New Revision: 3621

Modified:
   common-logging-log4j/trunk/src/main/java/org/jboss/logging/filter/TCLFilter.java
Log:
JBLOGGING-30 Fixed the TCLFilter to first check whether a ClassLoader is URLClassLoader, while retrieve URLs

Modified: common-logging-log4j/trunk/src/main/java/org/jboss/logging/filter/TCLFilter.java
===================================================================
--- common-logging-log4j/trunk/src/main/java/org/jboss/logging/filter/TCLFilter.java	2009-10-22 15:54:52 UTC (rev 3620)
+++ common-logging-log4j/trunk/src/main/java/org/jboss/logging/filter/TCLFilter.java	2009-10-22 15:56:48 UTC (rev 3621)
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.Method;
 import java.net.URL;
+import java.net.URLClassLoader;
 
 import org.apache.log4j.spi.Filter;
 import org.apache.log4j.spi.LoggingEvent;
@@ -103,9 +104,9 @@
       return ok;
    }
 
-   /** Start with the current thread context class loader 
+   /** Start with the current thread context class loader
     * @return true if the caller tcl has a url matching our deployURL
-    */ 
+    */
    private boolean isMatchingTCL()
    {
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
@@ -141,30 +142,41 @@
       return match;
    }
 
-   /** Use reflection to access a URL[] getURLs method so that non-URLClassLoader
-    class loaders that support this method can provide info.
+   /**
+    * First check if the <code>cl</code> is of type URLClassloader. If yes, then use the getURLs API without the
+    * need for reflection. If its not a URLClassloader type then go for reflection
+    * to access a URL[] getURLs method so that non-URLClassLoader
+    * class loaders that support this method can provide info.
     */
    private static URL[] getClassLoaderURLs(ClassLoader cl)
    {
       URL[] urls = {};
       try
       {
-         Class<?> returnType = urls.getClass();
-         Class<?>[] parameterTypes = {};
-         Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
-         if( returnType.isAssignableFrom(getURLs.getReturnType()) )
+         if (cl instanceof URLClassLoader)
          {
-            Object[] args = {};
-            urls = (URL[]) getURLs.invoke(cl, args);
+            URLClassLoader urlClassloader = (URLClassLoader) cl;
+            urls = urlClassloader.getURLs();
          }
-         if( urls == null || urls.length == 0 )
+         else
          {
-            getURLs = cl.getClass().getMethod("getClasspath", parameterTypes);
+            Class<?> returnType = urls.getClass();
+            Class<?>[] parameterTypes = {};
+            Method getURLs = cl.getClass().getMethod("getURLs", parameterTypes);
             if( returnType.isAssignableFrom(getURLs.getReturnType()) )
             {
                Object[] args = {};
                urls = (URL[]) getURLs.invoke(cl, args);
             }
+            if( urls == null || urls.length == 0 )
+            {
+               getURLs = cl.getClass().getMethod("getClasspath", parameterTypes);
+               if( returnType.isAssignableFrom(getURLs.getReturnType()) )
+               {
+                  Object[] args = {};
+                  urls = (URL[]) getURLs.invoke(cl, args);
+               }
+            }
          }
       }
       catch(Exception ignore)



More information about the jboss-svn-commits mailing list