JDK-8058202 : AnnotatedType implementations don't override toString(), equals(), hashCode()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8u20
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-09-03
  • Updated: 2019-05-22
  • Resolved: 2018-10-10
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.
JDK 12
12 b16Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
Implementations of java.lang.annotation.Annotation and java.lang.reflect.Type that are accessed via core reflection all provide reasonable implementations of equals, hashCode, and toString (even though the Type interface nor its sub-types actually require it per spec/documentation).

But the implementations of AnnotatedType have no such implementation. This can make them a pain to inspect when debugging code that uses AnnotatedTypes (especially since the internal fields of the actual implementations are not organized in a way that is intuitive unless one is more familiar with the actual internal implementation and the gory details of how type annotations are stored in class files).

JUSTIFICATION :
For consistency and ease of use when dealing with AnnotatedTypes. The Type interfaces are not spec'ed to implement these standard methods, but the implementations provided by core reflection implement them anyway. In fact Type#getTypeName() was added in Java 8, and goes a long way towards helping debug code that uses Type. AnnotatedType needs the same treatment.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It would be nice if the toString() method resulted in something very much like Type.toString(), except with annotations inline:

@A() java.util.List<@B() java.lang.String>
ACTUAL -
Instead, the implementation is inherited from java.lang.Object.toString():

sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl@d716361


Comments
Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-October/055937.html
08-10-2018

See implementations in src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java
15-08-2018

Overriding the toString implementation to be more informative would be a fine change.
11-05-2016