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

JVM throws ClassFormatError instead of NoClassDefFoundError.

    XMLWordPrintable

Details

    • sparc
    • solaris_2.4

    Description



      Name: akC45999 Date: 12/03/98



      Chapter 5.1.1 of the first specification revision reads :

        "Otherwise, if it is determined that the selected file is not a well-formed
        class file (pass 1 of 4.9.1) or is not of a class file of a supported major
        or minor version (?4.1), class or interface resolution throws a
        NoClassDefFoundError."

      Chapter 5.3.1 of the revised specification reads :

        "If the purported representation is not in ClassFile format (pass 1 of 4.9.1),
        or is not of a supported major or minor version, loading throws a
        ClassFormatError."

      This bug filed against JDK-116a.

      Following test makes attempt to load truncated class-file and gets
      ClassFormatError instead of NoClassDefFoundError.

      =============================== test.java ==================================

      import java.io.*;

      class myClassLoader extends ClassLoader {

        public synchronized Class loadClass(String name, boolean resolve) {

      Class c = null;
      try{
      c = findSystemClass(name);
      } catch (ClassNotFoundException e) {
      }

      if (c == null) {
      byte data[];

      try {
      FileInputStream in = new FileInputStream("badClass.class");
      data = new byte[in.available()];
      in.read(data);
      } catch (Exception e) {
      System.out.println(e);
      return null;
      }
      c = defineClass(data, 0, data.length);
      }
      return c;
        }
      }

      public class test {

        public static void main(String argv[]) throws ClassNotFoundException {

      myClassLoader c = new myClassLoader();
      c.loadClass("badClass");
        }
      }

      =============================== badClass.jcod ==================================

      class badClass {
        0xCAFEBABE;
        3; // minor version
        45; // version
        [] { // Constant Pool
          ; // first element is empty
          class #10; // #1
          class #12; // #2
          Method #2 #4; // #3
          NameAndType #6 #5; // #4
          Utf8 "()V"; // #5
          Utf8 "<init>"; // #6
          Utf8 "Code"; // #7
          Utf8 "LineNumberTable"; // #8
          Utf8 "SourceFile"; // #9
          Utf8 "badClass"; // #10
          Utf8 "badClass.java"; // #11
          Utf8 "java/lang/Object"; // #12
        } // Constant Pool

        0x0021; // access
        #1;// this_cpx
        #2;// super_cpx

        [] { // Interfaces
        } // Interfaces

        [] { // fields
        } // fields

        [] { // methods
          { // Member
            0x0001; // access
            #6; // name_cpx
            #5; // sig_cpx
            [] { // Attributes
              Attr(#7) { // Code
                1; // max_stack
                1; // max_locals
                Bytes[] {
                  0x2AB70003B1;
                };
                [] { // Traps
                } // end Traps
                [] { // Attributes
                  Attr(#8) { // LineNumberTable
                    [] { // LineNumberTable
                      0 1;
                    }
                  } // end LineNumberTable
                } // Attributes
      /* } // end Code
            } // Attributes
          } // Member
        } // methods

        [] { // Attributes
          Attr(#9) { // SourceFile
            #11;
          } // end SourceFile
        } // Attributes
      } // end class badClass
      */

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

      novo48% do
      java full version "JDK1.1.6N"
      java.lang.ClassFormatError: Truncated class file
      at java.lang.ClassLoader.defineClass(ClassLoader.java)
      at java.lang.ClassLoader.defineClass(ClassLoader.java)
      at KlassLoader.loadClass(test.java:24)
      at java.lang.ClassLoader.loadClass(ClassLoader.java)
      at test.main(test.java:37)
      novo48%

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

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

      Attachments

        Activity

          People

            foliversunw Fred Oliver (Inactive)
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: