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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 13 11:07:59 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-11-13 11:07:59 -0500 (Fri, 13 Nov 2009)
New Revision: 3694

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

Modified: common-logging-log4j/branches/2.1/src/main/java/org/jboss/logging/filter/TCLFilter.java
===================================================================
--- common-logging-log4j/branches/2.1/src/main/java/org/jboss/logging/filter/TCLFilter.java	2009-11-13 16:03:07 UTC (rev 3693)
+++ common-logging-log4j/branches/2.1/src/main/java/org/jboss/logging/filter/TCLFilter.java	2009-11-13 16:07:59 UTC (rev 3694)
@@ -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