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

VerifyError for malformed exception_table (start_pc >= end_pc) should be restored

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      There is unclear JVM behaviour with an exception which must be thrown
      when "start_pc" greater than "end_pc".

      The question is: what exception (VerifyError or ClassFormatError) must be really thrown?

      JVMS 2nd Edition, Chapter "4.7.3 The Code Attribute"
      (at http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#1546 )
      states:
        "...
          exception_table[]
        ...
          start_pc, end_pc
              The values of the two items start_pc and end_pc indicate the ranges in the code array at which the
              exception handler is active. The value of start_pc must be a valid index into the code array of the
              opcode of an instruction. The value of end_pc either must be a valid index into the code array of
              the opcode of an instruction or must be equal to code_length, the length of the code array. The value
              of start_pc must be less than the value of end_pc.

              The start_pc is inclusive and end_pc is exclusive; that is, the exception handler must be active while
              the program counter is within the interval [start_pc, end_pc).4
        ... "
      Thus, if "start_pc" is greater than "end_pc" then there should be thrown ClassFormatError.

      However, JVMS 2nd Edition, Chapter "4.9.2 The Bytecode Verifier"
      (at http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#9801 )
      states at the same time as follows:
        "...
          For each exception handler, the starting and ending point of code protected by the handler must be
          at the beginning of an instruction or, in the case of the ending point, immediately past the end
          of the code. The starting point must be before the ending point. The exception handler code must
          start at a valid instruction, and it may not start at an opcode being modified by the wide instruction.
        ..."
      In other words, if "start_pc" is greater than "end_pc" then there should be thrown VerifyError.


      That issue has a long story: before JDK5.0 there was VerifyError, but since JDK5.0 the ClassFormatError
      is thrown in such cases. So, in different versions of JDK we see different behaviour, though
      JVM spec does not clear in this point.

      In fact, the following jck15 tests was modified after fixing the JDK bug 4286567:
        vm/classfmt/atr/atrcod006/atrcod00601m1/atrcod00601m1.html
        vm/classfmt/atr/atrcod007/atrcod00701m1/atrcod00701m1.html
        vm/classfmt/atr/atrcod009/atrcod00901m1/atrcod00901m1.html
      to catch ClassFormatError intead of VerifyError.

      However, according with Gilad clarification the pre-1.5 (i.e. 1.4) behaviour should be restored.
      Please see comments.
      ###@###.### 2005-06-16 19:36:03 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              coleenp Coleen Phillimore
              Reporter:
              ygaevsky Yuri Gaevsky
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: