Handle generics in PreferJavaUtilObjectsRequireNonNull #538
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's changed?
Before this patch, the
PreferJavaUtilObjectsRequireNonNull
recipe would only migrate usage of exactlycheckNotNull(Object)
but not any other (sub)types such ascheckNotNull(String)
,checkNotNull(CustomType)
etc.We now match invocations of checkNotNull with exactly one or two arguments which makes the recipe more broadly applicable.
Note that there is also a three argument version that doesn't have a straight-forward replacement, I skipped that for now and added a testcase.
What's your motivation?
Migrate more usage of Preconditions.checkNotNull throughout our codebase.
Anything in particular you'd like reviewers to focus on?
The proposed implementation using refaster doesn't deal well with preserving the static import if one was used before. I'm not sure how to best handle that.
Anyone you would like to review specifically?
@timtebeek since you added refaster support.
Have you considered any alternatives or workarounds?
I have also tried modifying the method pattern to be
checkNotNull(*)
in no-guava.yml but that did not work as expected. I couldn't find other examples of using a wildcard match on an argument, maybe it isn't supported?Checklist