-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
minimal
-
-
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}.
- csr of
-
JDK-8266598 Exception values for AnnotationTypeMismatchException are not always informative
- Resolved