-
Type:
CSR
-
Resolution: Approved
-
Priority:
P3
-
Component/s: core-libs
-
None
-
source
-
minimal
-
-
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}
- csr of
-
JDK-8345319 Fix the tag type in PoolEntry and AnnotationValue
-
- Resolved
-