JDK-8335927 : Revisit AnnotationConstantValueEntry and AnnotationValue.OfConstant
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.classfile
  • Affected Version: 24
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-07-08
  • Updated: 2024-08-19
  • Resolved: 2024-08-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24 b11Fixed
Related Reports
CSR :  
Description
`AnnotationValue.OfConstant` is an arbitrary categorization in the JVMS for some of the single-CP-ref annotation values, including those for primitive types and strings; they can all resolved without class loading. `AnnotationConstantValueEntry` are constant pool entries that are referred to by such annotation values, all of which do not refer to other CP entries.

There are a few error-prone details in these two classes:

1. `AnnotationValue.OfConstant` can be evaluated without class loading into Objects in the runtime. However, this functionality is not exposed by OfConstant, and OfConstant returns the same ConstantDesc for boolean true and int 1. (This is manifested in our ClassPrinter output) Thus, we should add a new API to resolve the right Object.

2. `AnnotationConstantValueEntry` are entries that don't refer to other constants. However, themselves alone are not sufficient to create a value, as int, char, boolean, byte, short all share the IntegerEntry.

The solution taken is to note the difference between the constant pool and the Object representation of these constants; change constant to poolEntry and removing constantValue in favor of resolvedValue to facilitate the right usages, with API notes added. Remove the confusing `ConstantPoolBuilder::annotationConstantValueEntry`.

In addition, many methods can have more specific return types.
Comments
Changeset: 6af1d6ff Branch: master Author: Chen Liang <liach@openjdk.org> Date: 2024-08-13 15:14:06 +0000 URL: https://git.openjdk.org/jdk/commit/6af1d6ff210b3ddbc7d1585428b49631248a500b
13-08-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/20436 Date: 2024-08-02 00:39:12 +0000
02-08-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/20176 Date: 2024-07-14 22:30:43 +0000
14-07-2024