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

(thread) Thread constructors throw undocumented NPE for null name

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b36
    • CPU:
      generic
    • OS:
      generic

      Description

      Thread constructors assume that name is non-null. Since they have historically thrown NPE, it is likely that this should be documented. In the event that it is determined that null is a valid value, then getName() and setName() should be modified to be tolerant of null.

      TEST:

        $ cat Test.java
        public class Test {
            public static void main(String [] args) {
                new Thread((String)null);
            }
        }

      OUTPUT:

        $ 17; javac Test.java && java -showversion Test java version "1.7.0-ea"
        Java(TM) SE Runtime Environment (build 1.7.0-ea-b14)
        Java HotSpot(TM) Tiered VM (build 1.7.0-ea-b14, mixed mode)

        Exception in thread "main" java.lang.NullPointerException
              at java.lang.Thread.init(Thread.java:367)
              at java.lang.Thread.<init>(Thread.java:437)
              at Test.main(Test.java:3)
        $ 16; javac Test.java && java -showversion Test java version "1.6.0"
        Java(TM) SE Runtime Environment (build 1.6.0-b105)
        Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)

        Exception in thread "main" java.lang.NullPointerException
              at java.lang.Thread.init(Thread.java:349)
              at java.lang.Thread.<init>(Thread.java:419)
              at Test.main(Test.java:3)
        $ 15; javac Test.java && java -showversion Test java version "1.5.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
        Java HotSpot(TM) Server VM (build 1.5.0-b64, mixed mode)

        Exception in thread "main" java.lang.NullPointerException
              at java.lang.Thread.init(Thread.java:327)
              at java.lang.Thread.<init>(Thread.java:401)
              at Test.main(Test.java:3)
        $ 142; javac Test.java && java -showversion Test
        java version "1.4.2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
        Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

        Exception in thread "main" java.lang.NullPointerException
              at java.lang.Thread.init(Thread.java:289)
              at java.lang.Thread.<init>(Thread.java:360)
              at Test.main(Test.java:3)
        $ 14; javac Test.java && java -showversion Test java version "1.4.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
        Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

        Exception in thread "main" java.lang.NullPointerException
              at java.lang.Thread.init(Thread.java:291)
              at java.lang.Thread.<init>(Thread.java:362)
              at Test.main(Test.java:3)

        Attachments

          Activity

            People

            Assignee:
            chegar Chris Hegarty
            Reporter:
            iris Iris Clark
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: