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

jvm throws ClassCircularityError instead of ClassFormatError

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description



      Name: vrR10176 Date: 12/03/2002



      JDK1.4.2-b07 (and all previous) throws ClassCircularityError instead
      of ClassFormatError if default class loader tries to load interface
      which is its own superclass.

      The section 4.1 "The ClassFile Structure" of 2nd JVM spec says:
      "super_class
      ...
      For an interface, the value of the super_class item must always be a
      valid index into the constant_pool table. The constant_pool entry at
      that index must be a CONSTANT_Class_info structure representing the
      class Object."

      Moreover section 5.3.5 of the 2nd JVM spec describes the steps
      required to derive a class from a class file representation:

      Step1 says that first, the JVM determines whether is has already
      recorded that L is an initiating loader of a class or interface
      denoted by N. This is not true in this case, so step 1 can be
      ignored.

      Step 2 says that the JVM attempts to parse the purported
      representation. The following errors are detected at this phase:

      - ClassFormatError if the bytes violate any of the constraints
         set forth in sections 4.1 or 4.9.1
      - UnsupportedVersionError if the version is incorrect
      - NoClassDefFoundError if the name of the class is incorrect

      ClassCircularityError may be thrown by steps 3 or 4, but only
      if Step 2 has completed successfully. For this test case, Step 2
      cannot complete successfully, so ClassCircularityError must not be
      thrown.

      So if interface is its own superclass then class format checker
      must throw exactly ClassFormatError.

      To reproduce the issue execute following test.
      The test tries to load an interface which extends itself.

      ------------ test.java ------------------------
      public class test {
          public static void main(String args[]) {
              try {
                  Class.forName("test_interface");
                  System.out.println("Error: No exception");
              } catch (Throwable e) {
                  System.out.println("Exception: " + e);
      }
          }
      }

      ------------ test_interface.jcod --------------
      class test_interface {
        0xCAFEBABE;
        0; // minor version
        46; // major version
        [] { // Constant Pool
          ; // first element is empty
          class #2; // #1
          Utf8 "test_interface"; // #2
        } // Constant Pool

        0x0601; // access
        #1;// this_cpx
        #1;// super_cpx

        [] { // Interfaces
        } // Interfaces

        [] { // fields
        } // fields

        [] { // methods
        } // methods

        [] { // Attributes
        } // Attributes
      } // end class test_interface

      ------------ Logs -----------------------------
      %javac test.java
      %
      %jcod test_interface.jcod (see attachments for class files)
      %
      %java -version
      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b07)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b07, mixed mode)
      %
      %java -Xfuture test
      Exception: java.lang.ClassCircularityError: test_interface

      ------------------------------------------
      ClassFormatError is expected.

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

        Attachments

          Activity

            People

            Assignee:
            jloizeausunw Jane Loizeaux (Inactive)
            Reporter:
            rslasunw Rsla Rsla (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: