[concurrency-interest] NullPointerException in ThreadLocal$ThreadLocalMap.replaceStaleEntry

Doug Lea dl at cs.oswego.edu
Fri Jun 30 08:31:22 EDT 2006


Raj wrote:
> Hi we have been facing an NPE on an off. The stack trace looks like:
> 
> java.lang.NullPointerException
> 	at java.lang.ThreadLocal$ThreadLocalMap$Entry.access$502(ThreadLocal.java:229)
> 	at java.lang.ThreadLocal$ThreadLocalMap.replaceStaleEntry(ThreadLocal.java:509)
> 	at java.lang.ThreadLocal$ThreadLocalMap.getAfterMiss(ThreadLocal.java:362)
> 	at java.lang.ThreadLocal$ThreadLocalMap.get(ThreadLocal.java:341)
> 	at java.lang.ThreadLocal$ThreadLocalMap.access$000(ThreadLocal.java:219)
> 	at java.lang.ThreadLocal.get(ThreadLocal.java:121)
> *snip*
> 
> This issue has been reported by some elsewhere:
> http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=13741787&cat=10&thread=90185&treeDisplayType=threadmode1&forum=176#13741787.
> However, no solution/analysis of the cause has been posted.
> 

Which probably stems from no one having taken the time to
file a replicatable bug report so someone can diagnose it!
Could you please do so?

As Joe just mentioned, there was an unsupported usage (that
was not clearly documented as unsupported) of initialValue
methods recursively creating other ThreadLocals, that was
addressed for Mustang, and which might conceivably cause this.
It might not be too hard to look in your code to see if
there are any cases of this. Otherwise, offhand, this looks
like it might be a GC bug, but no one will be able to figure
it out unless they can replicate.

-Doug


More information about the Concurrency-interest mailing list