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

Raj qweries at gmail.com
Fri Jun 30 09:04:01 EDT 2006


Thanks for pointing out the initialValue bug. It is a good start to
narrow down the problem. It is not easy for us to do a code walk
through and find out if we are facing the same issue as we use some
third party libraries and the thread locals are being created in our
code, the libraries and presumably in the jdk code.

I will attempt checking the StackTraceElements in the ThreadLocal
constructor to see if the ThreadLocal.initialValue() is in the stack.
Figuring out how it would cause this NPE would be another thing. :)

Since it is not very easily reproducible, there would not be any quick
way to confirm if JDK 5 has the fix even if we do not face the issue
with JDK 5.

Thanks,
Raj

On 6/30/06, Doug Lea <dl at cs.oswego.edu> wrote:
> 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