Tuesday, September 05, 2006

Log NullPointerException when starting Tomcat

if you find the following stacktrace when starting Tomcat with commons-logging-1.1.jar and log4j:


java.lang.NullPointerException
at org.apache.log4j.Category.isEnabledFor(Category.java:757)
at org.apache.commons.logging.impl.Log4JLogger.isTraceEnabled(Log4JLogge
r.java:327)


It seems to be related to a bug in commons-logging related to the implementation of support for trace-level logging. Replace it with and older version (such as 1.0.4). At least for me it worked pretty well. It seems that commons-logging passes a wrong parameter to log4j.

I commented it in Tomcat bug 39090 (actually the same stacktrace is refered in 39631, but it was set as duplicated).

5 comments:

Marco said...

Hi,

the replacement with commons-logging-1.0.4.jar works for me too. Thanks !

best regards

Marco

Denis said...

Thanks a lot, seems to work for me, too. Been using commons-logging-1.1.jar before and got that sort of error.

Jeremy said...

Thanks for posting this: it saved me from having to figure it out on my own.

Cheers!

Sire Esectus said...

Saved my butt... thanks!

goldyard said...

Yes, you are right, I encount the same problem. This problem seems come from Log4JLogger.java and coursed by the following code:
try {
traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
} catch(Exception ex) {
// ok, trace not available
traceLevel = Priority.DEBUG;
}

I don't know why this traceLevel become a null when be transfered to Category.class?