8371960: Missing null check in AnnotatedType annotation accessor methods#28341
8371960: Missing null check in AnnotatedType annotation accessor methods#28341liach wants to merge 1 commit intoopenjdk:masterfrom
Conversation
|
👋 Welcome back liach! A progress list of the required criteria for merging this PR into |
|
@liach This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 23 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
I'm trying to judge the behavior/compatibility impact. Are there cases where NPE will be thrown for cases that is doesn't throw today? I get it that the parameter checking doesn't check it and instead the NPE comes from deep in the implementation, just want to understand if there is any impact of the change or not. |
|
There are impact to the 3 methods:
For these two methods:
They currently already throw NullPointerException from within AnnotationSupport.getIndirectlyPresent. The only action that happens before is a Map.get call, so I don't think the lifted null check would hide any existing linkage error or other exceptions. I think the main impact of this change is that |
Yes, it seems this will really only be noticed if getAnnotatedReturnType/getAnnotatedParameterTypes/etc. methods are used and something has a bug that results in invoking AnnotatedType methods with null. Seems low risk. |
| for (var impl : implementations()) { | ||
| var clazz = impl.getClass(); | ||
| if (!set.add(clazz)) { | ||
| fail("Duplicate implementation class %s in %s".formatted(clazz, impl)); |
There was a problem hiding this comment.
Good sanity test on the method source.
|
Thanks for the reviews! /integrate |
|
Going to push as commit b6d83ed.
Your commit was automatically rebased without conflicts. |
AnnotatedElementmethods specify they throw NPE if they take any null argument:isAnnotationPresent,get(Declared)Annotation,get(Declared)AnnnotationsByType. However,AnnotatedTypehas implementation quality issues that it does not throw NPE forisAnnotationPresentandget(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.Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28341/head:pull/28341$ git checkout pull/28341Update a local copy of the PR:
$ git checkout pull/28341$ git pull https://git.openjdk.org/jdk.git pull/28341/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28341View PR using the GUI difftool:
$ git pr show -t 28341Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28341.diff
Using Webrev
Link to Webrev Comment