JDK 9 RFR of JDK-8162817: Annotation toString output not reusable for source input

joe darcy joe.darcy at oracle.com
Mon Aug 1 21:39:41 UTC 2016


As pointed out by recent core-libs-dev traffic ([1] [2]), the toString 
output for annotation objects cannot be directly reused as source input 
if the annotation values are any of:

* Class values of array classes (uses JVM name)
* Arrays (output uses brackets ("[]") rather than braces {"{}")

In addition, there are problems with other situations including:

* Strings don't have surrounding " characters.

* Chars don't have surrounding ' charcters.

* Long values outside of the int range don't have a "L" suffix.

Please review the webrev for the change addressing these shortcomings:

     JDK-8162817: Annotation toString output not reusable for source input
     http://cr.openjdk.java.net/~darcy/8162817.1/

This change should cover 99 44/100 % of the annotation values that 
appear in practice; limited efforts were taken quoting characters in 
strings, etc.

The basic approach is to introduce a family of overloaded toSourceString 
methods to wrap/filter different kinds of values coupled with methods to 
convert the various primitive arrays to Stream<String> for final 
processing by a shared method to surround an array by "{" and "}" and 
add comma separators as needed.

Thanks,

-Joe

[1] 
http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-July/042637.html

[2] 
http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-July/042645.html



More information about the core-libs-dev mailing list