Bug 40159 - NullPointerException in org.apache.log4j.NDC.get
NullPointerException in org.apache.log4j.NDC.get
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Other
1.2
Other other
: P2 normal
: ---
Assigned To: log4j-dev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2006-08-02 04:17 UTC by Curt Arnold
Modified: 2014-02-17 13:47 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Curt Arnold 2006-08-02 04:17:08 UTC
Giesen Giesen wrote to log4j-users on 2006-07-10:

I sporadically get the following error when my JSF app starts up.
Anyone know what I can do? Would the 1.3 alpha version help? (I hate
to use prerelease software)

Exception sending context initialized event to listener instance of
class com.sun.faces.config.ConfigureListener
java.lang.NullPointerException
	at org.apache.log4j.NDC.get(NDC.java:209)
	at org.apache.log4j.spi.LoggingEvent.getNDC(LoggingEvent.java:238)

----

Google searching for NDC.get did find other mentions of NPE being thrown at the
same location.  The stack trace is consistent with ht == null, however ht is
expected to be initialized at class load and is not changed in the log4j code
base, however the field is neither static or final so there is nothing
preventing client code from changing its value.  The log4j 1.3 implementation is
substantially different.

The committed patch checks whether ht != null before calling get() and should
avoid the NPE, but would be nice to know the mechanism by which it got that way.
Comment 1 Curt Arnold 2006-08-02 04:19:28 UTC
Patch committed in rev 427881.  Waiting for feedback before marking as closed.
Comment 2 Steven Rasschaert 2006-11-22 04:12:09 UTC
Hello,

This problem does also occur in the MDC.
I got the NullPointerException in NDC.get() as mentioned here and now in the
MDC.get(). I think both are related to each other, so that's why I added this
comment here.
The exceptions are raised in my case, when I trigger a reload of a Tomcat
context which uses Log4j as the logging system.
Tomcat reloads the context and then:
- before Log4j 1.2.14: NullPointerException at NDC.get (as mentioned here)
- now: NullPointerException at MDC.get(). There propably the tlm==null.

Can this be fixed too with a "not-null-check" in the next release of Log4j as
was done with NDC.get()?

Thanks
Comment 3 Henri Yandell 2007-03-13 12:40:49 UTC
Reopening so Steven's comment gets noticed.
Comment 4 Curt Arnold 2007-08-21 14:02:09 UTC
Split off MDC issue as bug 43181 since 40159 was reported as resolved in log4j 1.2.14 release notes.  
MDC fix committed in rev 568278.