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

Javadoc for java.lang.Thread constructor is nonsense

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.1
    • docs
    • beta2
    • generic, x86
    • generic, windows_2000



      Name: bsC130419 Date: 07/24/2001


      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      Have a look at the JavaDoc for the java.lang.Thread default constructor. The
      Java example is absolute nonsense, here it is with my comments:

      class plain01 implements Runnable {
               String name;
               plain01() {
                   name = null; // NOT NEEDED
               }
               plain01(String s) {
                   name = s;
               }
               public void run() {
                   if (name == null)
                       // THIS LINE BELOW IS NOT TRUE - NO THREAD HAS BEEN CREATED
                       // ANY OBJECT COULD CALL new plain01().run()
                       System.out.println("A new thread created");
                   else
                       // AND AGAIN, NO THREAD HAS BEEN CREATED, JUST A plain01
                       System.out.println("A new thread with name " + name +
                                          " created");
               }
           }
           class threadtest01 {
               public static void main(String args[] ) {
                   int failed = 0 ;

                   Thread t1 = new Thread();
                   if (t1 != null) // t1 CANNOT BE NULL AT THIS POINT
                       System.out.println("new Thread() succeed");
                   else {
                       System.out.println("new Thread() failed");
                       failed++;
                   }
               }
           }

      THe ThreadTest01 class does not use plain01 - I'm guessing the intention. But
      the javadoc states: "Threads created this way [no arg constructor] must have
      overridden their run() method to actually do anything". The above example
      doesn't do that at all.
      (Review ID: 127945)
      ======================================================================

            shommel Scott Hommel (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: