-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
minimal
-
-
Other
Summary
This change proposes to always throw an AnnotationTypeMismatchException if the type of an annotation member is changed and the member is accessed for an annotation that was compiled prior to this change. The javadoc for AnnotationTypeMismatchException documents that this exception is intended for this purpose but is not currently thrown out of an oversight in the annotation parser implementation.
Problem
If an annotation member type is changed from being an enum to an annotation or vice versa, the current implementation of the annotation parser in the reflection API throws a NullPointerException upon processing a previously compiled annotation. This is the result of that change not being explicitly handled in the code. Unfortunately, the null pointer is already thrown when processing the annotation as no exception proxy is generated. This makes the entire annotation inaccessible as parsing an annotation is impossible and always yields the error, even if another, compatible member is supposed to be accessed.
Solution
Change the existing implementation to throw an AnnotationTypeMismatchException if a member type is changed from an enum to an annotation type or vice versa. This avoids the null pointer altogether.
Specification
The behavior is already specified in the annotation parser's javadoc but currently incorrectly implemented.
/**
* (...)
*
* The member must be of the indicated type. If it is not, this
* method returns an AnnotationTypeMismatchExceptionProxy.
*/
public static Object parseMemberValue(Class<?> memberType,
ByteBuffer buf,
ConstantPool constPool,
Class<?> container);
- csr of
-
JDK-8228988 AnnotationParser throws NullPointerException on incompatible member type
- Resolved