jvmgcprof icon indicating copy to clipboard operation
jvmgcprof copied to clipboard

Slight chance of NullPointerException in the GcProf.getloader

Open tootedom opened this issue 13 years ago • 0 comments

Hi there,

Thanks for open sourcing the lib. Thought I'd let you know of race condition that I came across the once during trying out the tool:

Exception in thread "Thread-0" java.lang.NullPointerException at GcProf.getloader(GcProf.java:232) at GcProf.getClass(GcProf.java:205) at GcProf.getnwork(GcProf.java:115) at GcProf.access$100(GcProf.java:24) at GcProf$1.run(GcProf.java:62)

There's a slight chance that between the Thread[] active = new Thread[g.activeCount()]; and the g.enumerate(active); that a thread has died (or possibily started).

In the case where a thread has died (and there's less threads returned than the array size), you can get a null pointer exception as a result of the attempt to get the classloader from a non existent thread.

loader = t.getContextClassLoader();

Could be solved by either a check on the return int from the g.enumerate and using that for the forloop, or null check on the t reference.

cheers /dom

tootedom avatar Feb 26 '12 13:02 tootedom