commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 9845] New: - Default LogFactory Implementation fails for Log4J
Date Thu, 13 Jun 2002 16:26:07 GMT
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=9845>.
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=9845

Default LogFactory Implementation fails for Log4J

           Summary: Default LogFactory Implementation fails for Log4J
           Product: Commons
           Version: 1.0 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Logging
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: jerome.jacobsen@gentootech.com


I've got Log4J 1.1.3 JAR in my classpath.  Upon startup of my application 
(actually a JUnit test case), I immediately get:

java.lang.ExceptionInInitializerError: 
org.apache.commons.logging.LogConfigurationException: 
java.lang.ClassCastException

So I downloaded the Commons Logging 1.0 source and debugged.  The problem is in 
org.apache.commons.logging.impl.LogFactoryImpl.guessConfig().

Class proxyClass=findClassLoader().
  loadClass( "org.apache.commons.logging.Log4jFactory" );

The above loadClass call should be changed to:

Class proxyClass=findClassLoader().
  loadClass( "org.apache.commons.logging.impl.Log4jFactory" );

However, after I make the above change I still get a ClassCastException, now 
from org.apache.commons.logging.LogFactory.newFactory().  This exception  
baffles me.  It happens at: 

return (LogFactory) clazz.newInstance();

So I modify newFactory() to do the newInstance() and the return in two steps 
instead of one.

Object result = clazz.newInstance();
return (LogFactory)result;

The exception occurs during the cast of result.  If I print result's class name 
I get org.apache.commons.logging.impl.LogFactoryImpl.  But checking if result 
is an instanceof org.apache.commons.logging.impl.LogFactoryImpl returns false.

Object result = clazz.newInstance();
System.out.println("Got Factory: " + result.getClass().getName());

if (result instanceof LogFactory) {
  System.out.println("result is a LogFactory");
}

if (result instanceof org.apache.commons.logging.impl.LogFactoryImpl) {
  System.out.println("result is a LogFactoryImpl");
}

return (LogFactory) result;

The code above just prints:
Got Factory: org.apache.commons.logging.impl.LogFactoryImpl

And then throws the ClassCastException.  I'm confused.

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


Mime
View raw message