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

4.7.2: reject ConstantValue attributes on non-static fields

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 21
    • specification
    • vm

      The ConstantValue attribute is specified to be "silently ignored" if the associated field has its ACC_STATIC flag set.

      In practice, HotSpot treats a ConstantValue attribute appearing on a non-static field as a "non-predefined" attribute, not only ignoring the body of the attribute, but also ignoring duplicates, despite the rule that "There may be at most one ConstantValue attribute in the attributes table of a field_info structure".

      This sort of flag-dependent categorization of attributes (as determined by ACC_STATIC) is not supported by 4.7, and envisions a finer-grained distinction between predefined and non-predefined attributes than the specification is equipped to handle. Of course, we can make a special-case rule, but the added complexity does not seem justified.

      A non-static field with this attribute very likely expects the attribute to have some effect, and the creator of the class file would benefit from having the issue flagged at class loading. Non-static fields of existing classes are unlikely to have the attribute at all, since it has no run time effect.

      Proposed change: or class or interface with ConstantValue applied to a non-static field violates format checking, and should fail to load.

            dlsmith Dan Smith
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: