logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Endre StĂžlsvik <En...@Stolsvik.com>
Subject Re: NullPointerException in org.apache.log4j.NDC.get
Date Tue, 08 Aug 2006 09:09:05 GMT

Curt Arnold wrote:
> On Jul 10, 2006, at 2:58 PM, Giesen Giesen wrote:
>> I'm using 1.2.11, but in my Internet searching, I've seen someone else
>> getting the exact same error in 1.2.13 (google: NullPointerException
>> org.apache.log4j.NDC.get). I will upgrade my app.
> Looks like several other people have run into the problem and have never 
> taken the effort to identify the underlying problem (whether ht == null 
> or Thread.getCurrentThread() == null) and report a bug against it.  It 
> would be pretty simple to put a guard around the access to the 
> Hashtable.get() call to avoid the NPE, but it would be nice to know how 
> things are getting into the state where they are needed.
>> Why would Thread.getCurrentThread() return null? Shouldn't that always
>> return a non-null value?
> The original authors of that section of code assumed that 
> Thread.getCurrentThread() would always be non-null.

Wouldn't it be way better to use ThreadLocals? They're much faster on 
newer javas (above 1.3, I think) than they used to be (They used to be a 
map keyed on thread, while the map is now in Thread, keyed on the 
ThreadLocal, which ensures unsynched access and way faster operation). 
At any rate it should be as fast as implementing a proprietary ThreadLocal.


View raw message