Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8058202

AnnotatedType implementations don't override toString(), equals(), hashCode()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 12
    • Component/s: core-libs
    • Labels:

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: