-
Type:
CSR
-
Resolution: Approved
-
Priority:
P4
-
Component/s: core-libs
-
None
-
behavioral
-
low
-
-
Java API
-
Implementation
Summary
Add null checks to AnnotatedType methods inherited from AnnotatedElement, where they are specifed to throw NPE for null.
Problem
AnnotatedElement specifies the following methods to throw NPE for null arguments:
isAnnotationPresentgetAnnotationgetDeclaredAnnotationgetAnnotationsByTypegetDeclaredAnnotationsByType
The implementation of the first 3 methods in AnnotatedType implementations do not throw NPE for null arguments.
Solution
Introduce new NPE for calling the first 3 methods on AnnotatedType with null argument.
The NPE has been conventional in all system AnnotatedElement implementations besides AnnotatedType. Loosening the NPE restriction would be more confusing than helpful.
In addition, get(Declared)AnnotationsByType already throw NPE. If users have relied on the 3 methods not failing on null, they likely would have noticed this inconsistency and reported an issue, so tighting the first 3 methods would be reasonable.
Specification
No specification change. This is purely behavioral, to correct AnnotatedType implementations to be compliant.
- csr of
-
JDK-8371960 Missing null check in AnnotatedType annotation accessor methods
-
- Resolved
-
- relates to
-
JDK-8371954 Document null handling in core reflection APIs
-
- Finalized
-