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

Race condition in class initialization

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • unknown
    • tools
    • None
    • sparc
    • solaris_2.6

      System is a Ultra 30/256MB ram.

      I'm using the SunSoft JDK1.1.5 release with
      native threads but the problem also occurs
      using the JavaSoft JDK1.1.6 with native
      threads.

      If you run the sample application it crashes
      with:

      java.lang.NullPointerException
      at Fred$1.construct(Fred.java:13)
      at Fred$2.run(Fred.java:31)
      at java.lang.Thread.run(Thread.java)


      Like I said, bizarre.


      public class Fred {
         
         public String s = "hello";
        
         public void doIt() {
            Worker w = new Worker();
            
            Worker worker = new Worker() {
               public void construct() {
                  System.out.println("This Fails");
                  s = "Hello There";
               }
            };
         }
         
         public static void main(String[] args) {
            Fred f = new Fred();
            f.doIt();
         }
          
         class Worker {
            public void construct() {
               System.out.println("This Works");
               s = "Hello There";
            }
            public Worker() {
               Runnable doConstruct = new Runnable() {
                  public void run() {
                     construct();
                  }
               };
               Thread thread = new Thread(doConstruct);
               thread.start();
            }
         }
      }

      peter.castle@rsa 1998-07-06
      peter.castle@rsa 1998-07-21

            dstoutamsunw David Stoutamire (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: