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

no NoClassDefFoundError when failed static initialization for multithreading

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2alpha2
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: szC45993 Date: 05/07/97



      The Java Virtual Machine, chapter 2 Concepts,
      section 2.16.5 Detailed Initialization Procedure, claims:

      "
      ...
      Class object contains state that can indicates one of four situations:
      ...
       - This Class object is in an erroneous state, perhaps because the verification or preparation step failed, or because initialization was attempted and failed.
      ...
      The procedure for initializing a class or interface is then as follows:
      ...
      5. If the Class object is in an erroneous state, then initialization is not possible. Release the lock on the Class object and throw a NoClassDefFoundError.
      "

      Meanwhile, undermentioned test shows that the NoClassDefFoundError is not arisen
      when the initialization was attempted and failed, for example, under the dividing on zero.

      Note that NoClassDefFoundError is correctly arisen in the case when Class object
      is in an erroneous state because the verification failed.

      The test gives the following mistaken result (jdk_1.1.2):
      ----------------------------------------------------------------------------
      INITIALIZATION BEGIN ExceptionInInitializerError! k = 5; excb.mthd(1) k = 5; excb.mthd(2) k = 5; excb.mthd(3) k = 5; excb.mthd(4) k = 5; excb.mthd(5)
      ----------------------------------------------------------------------------

      All other 4 threads must print " NoClassDefFoundError! " message but don't
      which means NoClassDefFoundError is not arisen properly.

      See sources below.

      --------------------- execution05201.java
      //File: %Z%%M% %I% %E%
      //Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.execution.execution052.execution05201;

      import java.io.PrintStream;
      import java.lang.*;

      public class execution05201 {

        public static int run(String argv[], PrintStream out) {

      try{
      execution05201a exca1 = new execution05201a();
      exca1.num = 1;
      Thread thr1 = new Thread(exca1);
      thr1.start();

      execution05201a exca2 = new execution05201a();
      exca2.num = 2;
      Thread thr2 = new Thread(exca2);
      thr2.start();

      execution05201a exca3 = new execution05201a();
      exca3.num = 3;
      Thread thr3 = new Thread(exca3);
      thr3.start();

      execution05201a exca4 = new execution05201a();
      exca4.num = 4;
      Thread thr4 = new Thread(exca4);
      thr4.start();

      execution05201a exca5 = new execution05201a();
      exca5.num = 5;
      Thread thr5 = new Thread(exca5);
      thr5.start();


      if (thr1.isAlive()){
      thr1.join();
      }
      if (thr2.isAlive()){
      thr2.join();
      }
      if (thr3.isAlive()){
      thr3.join();
      }
      if (thr4.isAlive()){
      thr4.join();
      }
      if (thr5.isAlive()){
      thr5.join();
      }

      } catch (Throwable e) {
      out.println("TRACE: Error/Exception in execution05201: "+ e);
      return 2;
      };

      out.println(execution05201c.str);
      return execution05201c.res;

        }

        public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
      }
      --------------------- execution05201a.java
      //File: %Z%%M% %I% %E%
      //Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.execution.execution052.execution05201;

      class execution05201a implements Runnable {

        public int num;

        public void run() {

      execution05201b excb = null;

      ///////////////////////////////////////////////////////////////////////////////
      //The attempt of the class execution05201b initialization must be here:
      ///////////////////////////////////////////////////////////////////////////////
      try{
      excb = new execution05201b();
      excb.mthd(num);
      } catch (ExceptionInInitializerError e) {
      execution05201c.str = execution05201c.str.concat(" ExceptionInInitializerError! ");
      if (execution05201c.str.indexOf("INITIALIZATION BEGIN") != -1) {
      execution05201c.put(5);
      }
      } catch (NoClassDefFoundError e) {
      execution05201c.str = execution05201c.str.concat(" NoClassDefFoundError! ");
      if (execution05201c.str.indexOf("INITIALIZATION BEGIN") != -1
      && execution05201c.str.indexOf("INITIALIZATION END") == -1
      && (execution05201c.get() == 5
      || execution05201c.get() == 0)) {
      execution05201c.put(0);
      } else {
      execution05201c.put(2);
      }
      };
      ///////////////////////////////////////////////////////////////////////////////
      execution05201c.str = execution05201c.str.concat(" k = "+excb.k+"; ");
      execution05201c.str = execution05201c.str.concat(" excb.mthd("+num+") ");

        }

      }
      --------------------- execution05201b.java
      //File: %Z%%M% %I% %E%
      //Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.execution.execution052.execution05201;

      public class execution05201b {
        static int i = 1;
        static int j = 1;
        static int k = 5;

        static {
      execution05201c.str = execution05201c.str.concat("INITIALIZATION BEGIN");
      long ibtime = System.currentTimeMillis();
      long ietime = ibtime;
      i += 1;
      j += 1 / (i - 2);
      k = 7;
      execution05201c.str = execution05201c.str.concat("INITIALIZATION END");
        }

        public static void mthd(int num) {
      i += j;
        }

      }
      --------------------- execution05201c.java
      //File: %Z%%M% %I% %E%
      //Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package javasoft.sqe.tests.vm.execution.execution052.execution05201;

      import java.io.PrintStream;

      public class execution05201c {
      public static int res = 2;
      public static String str = "";

        public static synchronized void put(int r) {

      res = r;
        }

        public static synchronized int get() {

      return res;
        }
      }
      ---------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            sliangsunw Sheng Liang (Inactive)
            Reporter:
            zsssunw Zss Zss (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: