Fix Version/s: 14
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
Make the output of the toString for annotation objects consistent between core reflection and javac.
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.
Make the output consistent in both situations. Examining javadoc output for consistency will be done as separate work.
No specification update as the exact toString output is, by design, not specified. The behavior changes are:
- 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.