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

Java initializes classes it shouldn't when compiled with -target 1.2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.3.0, 1.4.0
    • hotspot
    • beta2
    • generic
    • generic, solaris_7

      The following program when compiled with -target 1.2 should print

      Initializing A.

      but it prints

      Initializing A.
      Initializing B.

      As this is a gratuitous incompatibility with the previous (correct) runtime behavior when the program is compiled with -target 1.1, this bug must be fixed in order to change the default to -target 1.2 for Merlin javac.

      Note that according to the JVM specification the invokestatic instruction is only supposed to initialize the class which declared the resolved method, which in this case is A. There is nothing in the execution of this program that should cause B to be initialized.

           1
           2 class A {
           3 static void foo() {}
           4 static { System.out.println("Initializing A."); }
           5 }
           6
           7 class B extends A {
           8 static { System.out.println("Initializing B."); }
           9 }
          10
          11 class Test {
          12 public static void main(String[] args) {
          13 B.foo();
          14 }
          15 }
          16

            foliversunw Fred Oliver (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: