Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8171132 Improve class reading of invalid or out-of-range ConstantValue attributes
  3. JDK-8179983

Release Note: Add compile-time check for invalid or out-of-range ConstantValue attributes

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 9
    • 9
    • tools
    • Verified

      The classfile format (see JVMS section 4.7.2) defines an attribute called `ConstantValue` which is used to describe the constant value associated with a given (constant) field. The layout of this attribute is as follows:

      ```
      ConstantValue_attribute {
          u2 attribute_name_index;
          u4 attribute_length;
          u2 constantvalue_index;
      }
      ```
      Historically, `javac` has never performed any kind of range validation of the value contained in the constant pool entry at `constantvalue_index`. As such, it is possible for a constant field of type e.g. `boolean` to have a constant value other than `0` or `1` (the only legal values allowed for a boolean). Starting from <version>, `javac` will start detecting ill-formed `ConstantValue` attributes, and report errors if out-of-range values are found.

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: