DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10825>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10825

NullPointException when Logger.getClassLoader returns null

[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |



------- Additional Comments From [EMAIL PROTECTED]  2002-10-17 10:29 -------
This bug is still unsolved in the current CVS version (2002-10-17), so I decided
to reopen it again.
This bug occurs when the commons-logging classes are loaded by the bootstrap
class loader and no context class loader is available.
A patch as well as an appropriate test case is attached. This test makes use of
the Java endorsed library mechanism to expose the critical classes to the boot
strap class loader, so you will need a JDK that supports that mechanism to make
the test work. I used Sun J2SE SDK 1.4.0 on a Windows NT 4.0 machine.

The patch for LogFactory uses Class.forName() instead of
Class.getClassLoader().loadClass(). AFAIK this should not make a difference.
Furthermore this method is also available in pre 1.2 JDKs so it should not raise
any compatibility issues. 

Here is the modified newFactory method:

    protected static LogFactory newFactory(String factoryClass,
                                           ClassLoader classLoader)
            throws LogConfigurationException {
        try {
            if (classLoader != null) {
                try {
                    return (LogFactory) classLoader.loadClass(factoryClass)
                            .newInstance();
                } catch (ClassNotFoundException cnfx) {
                    // continue
                }
            }
            
            // class loader is null, or Factory class could not be loaded
            // by means of the specified class loader at this point.

            // Let's try the class loader that loaded this class. If this 
            // class is loaded by the bootstrap class loader 
            // Class.getClassLoader() can return null according to the 
            // contract of that method so we have to use Class.forName() 
            // instead of Class.getClassLoader().loadClass().
            return (LogFactory) Class.forName(factoryClass).newInstance();

        } catch (Exception e) {
            throw new LogConfigurationException(e);
        }
    }



To apply the patch enter the commons-logging directory and run "patch -Np0 <
patch.txt".

The patch applies changes to LogFactory.java and build.xml, and creates a new
TestCase called BootStrapTest.java

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>

Reply via email to