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

Clarify "optional" attributes like EnclosingMethod and Signature

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 8
    • Component/s: specification
    • Labels:
      None
    • Subcomponent:
      vm
    • Verification:
      Verified

      Description

      In the JVMS draft for Java SE 5.0, EnclosingMethod is added alongside InnerClasses and Synthetic as one of the attributes which "must be recognized and correctly read by a class file reader in order to properly implement the Java and Java 2 platform class libraries." It is therefore incongruous that the definition of EnclosingMethod says it is an _optional_ attribute, since the definitions of InnerClasses and Synthetic do not say they are optional.

      Signature is given an even more central billing - "The Signature attribute must be recognized and correctly interpreted by any Java virtual machine implementation that recognizes class files whose major version is 49.0 or above." - yet its definition says it is an _optional_ attribute. Meanwhile, the Runtime*Annotations and AnnotationDefault attributes did not have to be recognized and correctly interpreted by anyone, yet they were _not_ defined as optional, so they must be important to someone. (Indeed, their definitions said "The JVM must make these annotations available so they can be returned by the appropriate reflective APIs.")

      There are really three kinds of class file attributes:
      1. Essential to correct interpretation of the class file by the abstract JVM.
      2. Essential to correct interpretation of the class file by the broader Java SE platform (e.g. core reflection, or a Java compiler that reads class files when source code for classes is not available)
      3. Inessential to any part of the Java SE platform, but useful for tools.

      - ConstantValue, Code, StackMapTable, Exceptions, and BootstrapMethods are clearly of the first kind.
      - InnerClasses, EnclosingMethod, and Synthetic are of the second kind. Signature and Runtime*Annotations and AnnotationDefault too.
      - The third kind captures the sense of "optional" from 4.7: attributes which are predefined, but for whom "a class file reader may use the information they contain, or otherwise must silently ignore those attributes." An EnclosingMethod attribute is not optional when Class#getEnclosingMethod needs it to determine the enclosing method of a local or anonymous class; and a Signature attribute is not optional when Class#toGenericString needs it to determine a class signature. The truly optional attributes are SourceFile, SourceDebugExtension, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, and Deprecated.

      The upshot of all this is that:

      1. EnclosingMethod and Signature should not be defined as "optional" attributes.

      2. Signature should be listed with Runtime*Annotations and AnnotationDefault as an attribute which "must be recognized and correctly read by a class file reader in order to properly implement the Java SE platform class libraries [for 49.0 and above]."

      3. The 'attributes' items of ClassFile, field_info, method_info, and Code all enumerate the attributes they contain and require recognition of exactly those attributes. To reduce duplication, those items should simply say: "The attributes defined as appearing in the 'attributes' table of a ..., and the rules concerning recognition of those attributes, are given in 4.7."

      4. The 'attributes' table of field_info has always said "A field can have any number of attributes associated with it." but this has always been false as no more than one ConstantValue attribute in field_info.attributes. 4.5 should say "any number of optional attributes", in line with 4.6 and 4.7.3; all three should cross-ref "optional attributes" to 4.7.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abuckley Alex Buckley
                Reporter:
                abuckley Alex Buckley
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: