Uploaded image for project: 'CCC Migration Project'
  1. CCC Migration Project
  2. CCC-8162817

Annotation toString output not reusable for source input

XMLWordPrintable

    • behavioral
    • low
    • Some known dependencies on long-standing behavior.
    • Java API
    • Implementation

      Summary

      Improve the output of toString() on an annotation to be reusable as source input of an annotation.

      Problem

      If an annotation contained certain common constructs, such as arrays, the toString output for the annotation was not reusable as source code and did not match the source code syntax. For example, the toString output for arrays used brackets ("[]") rather than the braces ("{}") used in source.

      Solution

      Update the implementation to use source-compatible output for arrays, strings, characters, etc.

      Specification

      The exact toString output of an annotation is deliberately not specified; from java.lang.annotation.Annotation.toString():

      * Returns a string representation of this annotation.  The details
      * of the representation are implementation-dependent [...]

      Therefore, the details of the toString output of annotations are not a formally exported interface of the platform. Therefore, this request does not have any specification change associated with it.

      However, from various JDK regression tests which needed to be updated (JDK-8163113, JDK-8163231) as well as discussions on core-libs, there is evidence that various parties are dependent on the exact toString output.

      Therefore, this retroactive ccc request is being filed to note the compatibility impact.

      Behavioral changes include

      • Braces ("{}") rather than brackets ("[]") around arrays
      • String values have surrounding double quote characters (")
      • Char values have surrounding single quote characters (').
      • Long values outside of the int range have an "L" suffix.

            darcy Joe Darcy
            darcy Joe Darcy
            Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: