[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-cvs
Subject:    cvs commit: jakarta-log4j/src/java/org/apache/log4j/helpers Loader.java
From:       ceki () apache ! org
Date:       2001-10-11 15:10:21
[Download RAW message or body]

ceki        01/10/11 08:10:21

  Modified:    src/java/org/apache/log4j/helpers Loader.java
  Log:
  Search for "resource" using the thread context class loader under
  Java2. If that fails, search for "resource" using the class loader
  that loaded this class (Loader). Under JDK 1.1, only the the class
  loader that loaded this class (Loader) is used.
  
  Try one last time with ClassLoader.getSystemResource(resource)</code>,
  that is is using the system class loader in JDK 1.2 and virtual
  machine's built-in class loader in JDK 1.1.
  
  The difference with the previous code was that under Java2, the
  classloader of org.apache.log4j.helpers.Loader was *not* tried if the
  thread context loader was set. However, this is incorrect logic becase
  Thread.getContextClassLoader always returns a value.
  
  Thread.getContextClassLoader javadoc reads:
  
     Returns the context ClassLoader for this Thread. The context
     ClassLoader is provided by the creator of the thread for use by code
     running in this thread when loading classes and resources. If not set,
     the default is the ClassLoader context of the parent Thread. The
     context ClassLoader of the primordial thread is typically set to the
     class loader used to load the application.
  
  If an application server chooses not to set the thread context class
  loader, then Thread.getContextClassLoader returns the "classpath"
  classloader which usually not what is desired.
  
  Revision  Changes    Path
  1.15      +19 -7     jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java
  
  Index: Loader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Loader.java	2001/08/09 20:16:31	1.14
  +++ Loader.java	2001/10/11 15:10:21	1.15
  @@ -43,8 +43,10 @@
        <ol>
   
        <p><li>Search for <code>resource</code> using the thread context
  -     class loader under Java2 and using the class loader that loaded
  -     this class (<code>Loader</code>) under JDK 1.1.
  +     class loader under Java2. If that fails, search for
  +     <code>resource</code> using the class loader that loaded this
  +     class (<code>Loader</code>). Under JDK 1.1, only the the class
  +     loader that loaded this class (<code>Loader</code>) is used.
   
        <p><li>Try one last time with
        <code>ClassLoader.getSystemResource(resource)</code>, that is is
  @@ -63,10 +65,19 @@
       try {
         if(!java1) {
   	classLoader = Thread.currentThread().getContextClassLoader();	
  +	if(classLoader != null) {
  +	  LogLog.debug("Trying to find ["+resource+"] using context classloader "
  +		       +classLoader+".");
  +	  url = classLoader.getResource(resource);      
  +	  if(url != null) {
  +	    return url;
  +	  }
  +	}
         }
         
  -      if(classLoader == null)
  -	classLoader = Loader.class.getClassLoader(); 
  +      // We could not find resource. Ler us now try with the
  +      // classloader that loaded this class.
  +      classLoader = Loader.class.getClassLoader(); 
   
         LogLog.debug("Trying to find ["+resource+"] using "+classLoader
   		   +" class loader.");
  @@ -78,9 +89,10 @@
         LogLog.warn(TSTR, t);
       }
   
  -    // Attempt to get the resource from the class path. It may be the
  -    // case that clazz was loaded by the Extentsion class loader which
  -    // the parent of the system class loader. Hence the code below.
  +    // Last ditch attempt: get the resource from the class path. It
  +    // may be the case that clazz was loaded by the Extentsion class
  +    // loader which the parent of the system class loader. Hence the
  +    // code below.
       LogLog.debug("Trying to find ["+resource+
   		 "] using ClassLoader.getSystemResource().");
       return ClassLoader.getSystemResource(resource);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-cvs-help@jakarta.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic