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

Exception values for AnnotationTypeMismatchException are not always informative

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 17
    • core-libs
    • None
    • behavioral
    • minimal
    • Hide
      Users might catch this exception and rely on the current format of the property, for example in tooling to describe errors in annotation data. If the tooling would, for example, rely to find the descriptor in an error message. This tooling might break as a consequence of this patch.
      Show
      Users might catch this exception and rely on the current format of the property, for example in tooling to describe errors in annotation data. If the tooling would, for example, rely to find the descriptor in an error message. This tooling might break as a consequence of this patch.
    • Java API
    • Implementation

      Summary

      AnnotationTypeMismatchException provides a description of the found value via its foundType method. The content of the property is not explicitly defined but it might be expected to be in a certain format. The current format exposes Java descriptors and proxy types which make the exception's message - which contains this property - difficult to read. This change improves the readability of these messages.

      Problem

      The error messages are difficult to read for developers not familiar with the inner workings of the JVM and should use binary names and actual types rather then proxy types. For mismatched array's, the component's value should be represented as a character rather then an integer as the character is documented in the JVMS.

      Solution

      Replace the use of descriptors with binary names and replace proxy types representing an annotation with the annotation's actual value. Display an array's component type's character rather then the letter's integer representation if an array contains incompatible values.

      For example, the toString representations of an incompatible enumeration/annotation/array properties are altered as follows:

      /* Warning type mismatch! "Lpkg/SomeEnumeration;.VALUE" */
      /* Warning type mismatch! "some.AnnotationProxy$123[@pkg.SomeAnnotation()]" */
      /* Warning type mismatch! "Array with component tag: 64" */

      to

      /* Warning type mismatch! "pkg.SomeEnumeration.VALUE" */
      /* Warning type mismatch! "@pkg.SomeAnnotation()" */
      /* Warning type mismatch! "Array with component tag: @" */

      For enumerations, the internal descriptor is changed to the binary class name, annotations are displayed without their proxy type which does not contain any additional information and should be seen as an implementation detail, and the component type of an array is displayed as the JVMS (2-byte) character, rather then the character's integer representation,

      Specification

      The change is already implied by the current Javadoc:

       * Returns the type of data found in the incorrectly typed element.
       * The returned string may, but is not required to, contain the value
       * as well.  The exact format of the string is unspecified and the string
       * may be {@code null}.

            winterhalter Rafael Winterhalter
            winterhalter Rafael Winterhalter
            Joel Borggrén-Franck (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: