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

class initialization is omitted by jvm

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5

    Description



      Name: szC45993 Date: 02/11/98



      The new jvm spec reads (and it does not contradict to the old spec):

      5.7 Initialization, p. 159:
      "A class or interface may only be initialized as a result of:
      - The execution of any one the Java Virtual Machine's new, getstatic, putstatic, or invokestatic instructions that references the class or interface. Each of these corresponds to one of the conditions in $2.16.4."

      2.16.4 Initialization, p. 46:
      "A class or interface type T will be initialized immediately before one of the following occurs:
      - T is a class and an instance of T is created.
      - T is a class and static method of T is invoked."

      However, the JCK execution01602.html test shows that some cases
      exist when static initializer is not processed by the jdk1.2b3F jvm.

      See log and example below.


          LOG:

      novo7% setenv CLASSPATH /export/ld32/sqe/harness_release/classes:/export/home/JAVA/workdir/classes:.
      novo7% /export/ld14/java/dest/jdk1.2b3F/solaris/bin/javac clss1.java
      novo7% /export/ld14/java/dest/jdk1.2b3F/solaris/bin/java -verify clss1
      ERROR: static initializer of clss1 was not invoked!
      WRONG RESULT: ###< clss2 main >###
      SHOULD BE: ###< clss2 clss1 main >###

      The test works fine till jdk1.2b3F:

      novo7% /export/ld14/java/dest/jdk1.2b3E/solaris/bin/java -verify clss1
      ALL RIGHT!

          SOURCES:

      --------------------- clss1.java
      class clss2 {
        static String str = "clss2";
      }

      class clss1 {

        static {
      clss2.str = clss2.str.concat(" clss1");
        }

        public static void main(String argv[]) {

      clss2.str = clss2.str.concat(" main");

      if (clss2.str.indexOf("clss2 clss1 main") != -1) {
      System.out.println("ALL RIGHT!");
      System.exit(0);
      }

      System.out.println("ERROR: static initializer of clss1 was not invoked!");
      System.out.print("WRONG RESULT: ");
      System.out.println("###< "+clss2.str+" >###");
      System.out.print("SHOULD BE: ");
      System.out.println("###< clss2 clss1 main >###");

      System.exit(2);
        }
      }
      ---------------------

      Hook 5(hook5): test

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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: