-
Bug
-
Resolution: Fixed
-
P3
-
6u33, 7
-
b19
-
generic, x86
-
generic, windows_7
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8205855 | 11.0.1 | Liam Miller-Cushon | P3 | Resolved | Fixed | team |
JDK-8206327 | 8-pool | Deepak Kejriwal | P3 | Closed | Won't Fix | |
JDK-8206328 | 7-pool | Deepak Kejriwal | P3 | Closed | Won't Fix |
--------
Class.getAnnotation() throws an ArrayStoreException when the annotation class is not present in the classpath
OPERATING SYSTEM
----------------
All (tested on Windows and Solaris)
FULL JDK VERSION
----------------
JDK 5 and greater, including JDK 8
Note: The ArrayStoreException begin with 5.0u6 (See CR 6322301 fix).
PROBLEM DESCRIPTION from LICENSEE
---------------------------------
A call to Class.getAnnotation() throws the following java.lang.ArrayStoreException when an annotation's Class is not present on the classpath. The following stack is from JDK8-b39:
Exception in thread "main" java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:677)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:484)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:308)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:242)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3093)
at java.lang.Class.getAnnotation(Class.java:3052)
at AnnotationTest.doTest(AnnotationTest.java:9)
at AnnotationTest.main(AnnotationTest.java:5)
The API specification for java.lang.Class states that Class.getAnnotation() returns this element's annotation for the specified type if such an annotation is present, else null. ArrayStoreException is not a checked Exception so it doesn't have to be declared, but it effectively prevents the API from following the specification - either the annotation should be returned, or null. Currently neither happens.
The application could catch the ArrayStoreException and handle it, but Licensee prefers it to be dealt with in the JDK's internal implementation.
TESTCASE AND REPRODUCTION INSTRUCTIONS
--------------------------------------
Attached
WORKAROUND
----------
Catch the undocumented ArrayStoreException and handle it.
- backported by
-
JDK-8205855 (ann) Class.getAnnotation() throws an ArrayStoreException when the annotation class not present
-
- Resolved
-
-
JDK-8206327 (ann) Class.getAnnotation() throws an ArrayStoreException when the annotation class not present
-
- Closed
-
-
JDK-8206328 (ann) Class.getAnnotation() throws an ArrayStoreException when the annotation class not present
-
- Closed
-
- csr for
-
JDK-8198584 (ann) Class.getAnnotation() throws an ArrayStoreException when the annotation class not present
-
- Closed
-
- duplicates
-
JDK-7184242 java.lang.ArrayStoreException caused by sun.reflect.annotation.AnnotationParser
-
- Closed
-
- relates to
-
JDK-8198669 Refactor annotation array value parsing to reduce duplication
-
- Resolved
-
-
JDK-6322301 unknown annotations are not ignored in Class.getAnnotations
-
- Closed
-