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

VerifyError thrown if code_length is equal to 0

    XMLWordPrintable

Details

    • hopper
    • generic
    • generic

    Description



      Name: vrC94537 Date: 10/26/2000



      The section "4.7.3 The Code Attribute" of 2nd JVM spec says:
      "The value of code_length must be greater than zero; the code
      array must not be empty."

      If a value of code_length item of Code attribute is equal to 0,
      then the class file is malformed and therefore must be rejected
      by VM class format checker with exception ClassFormatError.
      However, JVM (all jdk version till jdk1.4.0beta-b37) throws
      VerifyError instead of ClassFormatError.

      To reproduce the issue execute following test.
      Test tries to load class file with code_length item set to 0.
      JVM must reject class test_n with exception ClassFormatError.

      ------------ test.java ------------------------
      public class test {

          public static void main(String args[]) {

              try {
                  Class badClass = Class.forName("test_n");
                  System.out.println("test failed to reject bad classfile test_n");
              } catch (Throwable e) {
                  System.out.println("Loading exception: " + e);
              }
          }

      }

      ------------ test_n.jcod ------------------------
      class test_n {
        0xCAFEBABE;
        3; // minor version
        45; // version

        [] { // Constant Pool
          ; // first element is empty
          class #3; // #1
          class #4; // #2
          Utf8 "test_n"; //3
          Utf8 "java/lang/Object"; // #4
          Utf8 "Code"; // #5
          Utf8 "<init>"; // #6
          Utf8 "()V"; // #7
        } // Constant Pool

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

        [] { // Interfaces
        } // Interfaces

        [] { // fields
        } // fields

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

        [] { // Attributes
        } // Attributes
      }

      ------------ Logs ------------------------
      %javac test.java
      %
      %jcod test_n.jcod
      %
      %java -version
      java version "1.4.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b37)
      Java HotSpot(TM) Client VM (build 1.4beta-B37, mixed mode)
      %
      %java -Xfuture test
      Loading exception: java.lang.VerifyError: (class: test_n, method: <init> signature: ()V) Empty code

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


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

      Attachments

        Activity

          People

            wtaosunw Wei Tao (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: