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

Revisit AnnotationConstantValueEntry and AnnotationValue.OfConstant

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 24
    • core-libs
    • None

      `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.

            liach Chen Liang
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: