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

Fix the tag type in PoolEntry and AnnotationValue

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 24
    • core-libs
    • None
    • source
    • minimal
    • Hide
      Changes to a feature before it is released has almost no behavioral impact. It is effectively changing a preview feature. One minor risk is that users who printed out annotation value tags may now see unexpected output values of integer instead of characters.
      Show
      Changes to a feature before it is released has almost no behavioral impact. It is effectively changing a preview feature. One minor risk is that users who printed out annotation value tags may now see unexpected output values of integer instead of characters.
    • Java API
    • SE

      Summary

      Widen the return type of AnnotationValue::tag and PoolEntry::tag from char and byte to int.

      Problem

      The constants for annotation value and constant pool tags are int fields, but these methods do not return int. Other union values indicating the type of union, such as TypeAnnotation.TargetType::targetTypeValue, or StackMapFrameInfo::frameType, return int. If the constant pool tags go beyond 127, the byte value will return an error-prone negative value indicating an unsigned byte value.

      Solution

      Widen the return type of AnnotationValue::tag and PoolEntry::tag from char and byte to int. Note the reason AnnotationValue::tag use int instead of char is for consistency.

      Specification

      --- a/src/java.base/share/classes/java/lang/classfile/AnnotationValue.java
      +++ b/src/java.base/share/classes/java/lang/classfile/AnnotationValue.java
      @@ -456,9 +456,11 @@ default ClassDesc classSymbol() {
            *
            * @apiNote
            * {@code TAG_}-prefixed constants in this class, such as {@link #TAG_INT},
      -     * describe the possible return values of this method.
      +     * describe the possible return values of this method.  The return type is
      +     * {@code int} for consistency with union indicator items in other union
      +     * structures in the {@code class} file format.
            */
      -    char tag();
      +    int tag();
      
           /**
            * {@return an enum value for an element-value pair}
      diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java
      index fdb8b497ff9..5762a92a061 100644
      --- a/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java
      +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java
      @@ -98,7 +98,7 @@ public sealed interface PoolEntry
            * {@code TAG_}-prefixed constants in this class, such as {@link #TAG_UTF8},
            * describe the possible return values of this method.
            */
      -    byte tag();
      +    int tag();
      
           /**
            * {@return the index within the constant pool corresponding to this entry}

            liach Chen Liang
            liach Chen Liang
            Adam Sotona
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: