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

Make javac's toString() on annotation objects consistent with core reflection

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      In the past downstream tools have parsed the toString output of annotations and have needed to be updated for changes.
    • Interface Kind:
      Java API
    • Scope:
      JDK

      Description

      Summary

      Make the output of the toString for annotation objects consistent between core reflection and javac.

      Problem

      There are a number of consistencies in the output of annotations (and the related AnnotationMirror the the annotation processing API) between core reflection and javac.

      Solution

      Make the output consistent in both situations. Examining javadoc output for consistency will be done as separate work.

      Specification

      No specification update as the exact toString output is, by design, not specified. The behavior changes are:

      For javac:

      • The string for class literals, either stand-alone or in an array now properly end in ".class".
      • For an enum constant, just the constant name is emitted rather than the full class name followed by the enum constant name. This shorter form is also used by javadoc.

      For core reflection:

      • Eliding "value=" when it is not necessary, logic already present for this in the javac implementations.
      • Changing the formatting of byte values to follow the existing javac convention, "(byte)0x1a"
      • Adopting the same quoting policy for char and string values as javac. This was accomplished by copying a few small methods from the javac internals; I don't think it is worthwhile to go through the contortions that would be needed to share this small bit of rarely changing code across these modules.
      • Unconditionally append a trailing "L" to long values, as done by javac.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              darcy Joe Darcy
              Reviewed By:
              Jonathan Gibbons, Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: