Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4403944

NullPointerException raised in java.lang.Thread.toString

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.2.1
    • core-libs
    • beta2
    • sparc
    • solaris_2.6
    • Verified



      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)
      ======================================================================

            jjb Josh Bloch (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: