Name: boT120536 Date: 01/11/2001
$ java -version
java version "1.2.1"
Solaris VM (build Solaris_JDK_1.2.1_03, native threads, sunwjit)
$ uname -a
SunOS crtsp1 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-Enterprise
An application I ran failed giving the following call stack:
java.lang.NullPointerException
at java.lang.Thread.toString(Thread.java:1062)
at java.lang.String.valueOf(Compiled Code)
at java.util.AbstractMap.toString(Compiled Code)
at com.db.ard.util.thread.ThreadManager.toString(Compiled Code)
at com.db.ard.util.thread.ThreadManager.finish(Compiled Code)
at com.db.ard.app.sync.Controller.main(Compiled Code)
The process ran successfully next time.
I have not been able to reproduce the problem but have looked
at the code in the java.lang.Thread class to see
if there was a potential problem. There is scope for this NullPointerException
in java.lang.Thread source code:
public String toString() {
if (getThreadGroup() != null) {
return "Thread[" + getName() + "," + getPriority() + "," +
getThreadGroup().getName() + "]";
} else {
return "Thread[" + getName() + "," + getPriority() + "," +
"" + "]";
}
}
...
public final ThreadGroup getThreadGroup() {
return group;
}
...
private void exit() {
if (group != null) {
group.remove(this);
group = null;
}
/* Aggressively null object connected to Thread: see bug 4006245 */
target = null;
}
As reference returned by getThreadGroup() is not copied to a local variable
in toString it is possible that the getThreadGroup() value returned changes to
null before the getThreadGroup().getName() call if the exit() is being called at
same time as toString().
(Review ID: 114888)
======================================================================