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

JVM rejects classfile with both static and non-static <clinit> methods

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_7

      Description



      Name: vsR10008 Date: 05/30/2000



      JVMS 2nd ed. (CHAPTER 3 "The Structure of the Java Virtual Machine", section 3.9
      "Specially Named Initialization Methods") reads:

      "A class or interface has at most one class or interface initialization method.
      ...
      The initialization method of a class or interface is static and takes no arguments.
      It has the special name <clinit>"

      Presence of two different <clinit> methods (static and non-static) is allowed because
      static <clinit> is class initializer but non-static is not; thus, there is only one
      class initializer in this case.

      The following test shows that JVM doesn't allow static and non-static <clinit>
      to coexist in classfile and is failed with exception java.lang.ClassFormatError:

      ------------------------------------------------------------------ c.jasm -----

      super public class c
      {

      public static Field a:I;

      public Method "<init>":"()V"
      stack 1 locals 1
      {
      aload_0;
      invokespecial Method java/lang/Object."<init>":"()V";
      return;
      }

      // It is not a class initializer
      Method "<clinit>":"()V"
      stack 1 locals 1
      {
      iconst_1;
      putstatic Field a:"I";
      return;
      }

      // class initializer
      static Method "<clinit>":"()V"
      stack 1 locals 1
      {
      iconst_2;
      putstatic Field a:"I";
      return;
      }

      }

      ------------------------------------------------------------------ t.java -----

      public class t {
          public static void main(String[] argv) {
              try {
                  if ( c.a == 2 ) {
                      System.out.println("PASSED!");
                  } else {
                      System.out.println("FAILED, a=" +c.a);
                  }
              } catch (Throwable t) {
                  System.out.println("FAILED: Exception "+t);
              }
          }
      }

      --------------------------------------------------------------------------------

      $ java -version
      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, interpreted mode)

      $ uname -a
      SunOS novo12 5.7 Generic_Patch sun4u sparc SUNW,Ultra-2

      $ jasm c.jasm

      $ javac -d . t.java

      $ java t

      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)

      This failure is reproduced in all builds of JDK 1.3 and JDK 1.2-1.2.2
      (and affects Classic and HotSpot both).

      In JDK 1.1-1.2_Beta4 failure is different: JVM invokes non-static
      <clinit> instead of static one (becase it is encountered first)

      In JDK 1.0,1.0.1,1.0.2,1.0beta2 this test is passed successfully.

      The complete run log (for all available JDKs):

      ---- 1.0 ----
      PASSED!
      ---- 1.0.1 ----
      PASSED!
      ---- 1.0.2 ----
      PASSED!
      ---- 1.0beta2 ----
      PASSED!
      ---- 1.1_Final ----
      FAILED, a=1
      ---- 1.1.1 ----
      FAILED, a=1
      ---- 1.1.2 ----
      FAILED, a=1
      ---- 1.1.3 ----
      FAILED, a=1
      ---- 1.1.4 ----
      FAILED, a=1
      ---- 1.1.5 ----
      FAILED, a=1
      ---- 1.1.6 ----
      FAILED, a=1
      ---- 1.1.7 ----
      FAILED, a=1
      ---- 1.1.7A ----
      FAILED, a=1
      ---- 1.1.7B ----
      FAILED, a=1
      ---- 1.1.8 ----
      FAILED, a=1
      ---- 1.2_EA2 ----
      FAILED, a=1
      ---- 1.2_Beta1 ----
      FAILED, a=1
      ---- 1.2beta2 ----
      FAILED, a=1
      ---- 1.2beta3 ----
      FAILED, a=1
      ---- 1.2beta4 ----
      FAILED, a=1
      ---- 1.2 ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.2.1 ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.2.2 ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.3beta ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.3.0 ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.3.0rc2 ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.3.0rc3 ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)
      ---- 1.4.0beta ----
      FAILED: Exception java.lang.ClassFormatError: c1 (Repeative method name/signature)

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wtaosunw Wei Tao (Inactive)
              Reporter:
              atwosunw A2 A2 (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: