JDK-8268729 : Use of simple names in AnnotationValue#toString after JDK-8164819 breaks some annotation processors
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2021-06-15
  • Updated: 2021-12-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
AnnotationValue#toString returns "a string representation of this value ... in a form suitable for representing this value in the source code of an annotation."

JDK-8164819 changed the implementation to be consistent with core reflection, and replaced the use of qualified names for types (in annotations and class literals) with simple names: http://hg.openjdk.java.net/jdk/jdk/rev/761b86d5563d#l2.24

That change made it harder to use the toString() representation in annotation-processor generated code, because the referenced types may require imports. I've encountered a number of annotation processors that assumed AnnotationValue.toString() would return a 'self-contained' representation of the annotation value that didn't require any additional imports.

Is it worth considering leaving the use of qualified names in AnnotationValue#toString, to make it easier to use the provided string representation in generated code?