-
CSR
-
Resolution: Approved
-
P4
-
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.
- csr for
-
JDK-8162817 Annotation toString output not reusable for source input
- Closed