RFR: 8371960: Missing null check in AnnotatedType annotation accessor methods
Chen Liang
liach at openjdk.org
Sun Nov 16 16:10:21 UTC 2025
`AnnotatedElement` methods specify they throw NPE if they take any null argument: `isAnnotationPresent`, `get(Declared)Annotation`, `get(Declared)AnnnotationsByType`. However, `AnnotatedType` has implementation quality issues that it does not throw NPE for `isAnnotationPresent` and `get(Declared)Annotation`.
This patch fixes this oversight by adding explicit null checks. For `get(Declared)AnnotationsByType`, even though it did throw exceptions, it was in the middle of parsing, so throwing it in the beginning is better.
-------------
Commit messages:
- Null checks for AnnotatedType
Changes: https://git.openjdk.org/jdk/pull/28341/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28341&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8371960
Stats: 105 lines in 2 files changed: 103 ins; 0 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/28341.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28341/head:pull/28341
PR: https://git.openjdk.org/jdk/pull/28341
More information about the core-libs-dev
mailing list