Repository navigation
Remove onOverrideMethodInvocationVarargsArrayNullability handler method
#1518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+230
−167
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
05ff43f
WIP
msridhar 40d5365
tests
msridhar f272019
tweak test
msridhar b8ab0a4
tweaks
msridhar c266af0
cleanup
msridhar 3b6d5a0
fixes
msridhar d7ba309
cleanup
msridhar 5328b0a
tweak
msridhar 97ec233
Merge branch 'master' into issue-1501
msridhar 6f02cdc
fix nullaway warnings
msridhar 9ab011d
Merge branch 'master' into issue-1501
msridhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
nullaway/src/main/java/com/uber/nullaway/MethodParameterNullness.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.uber.nullaway; | ||
|
|
||
| import com.sun.tools.javac.code.Symbol; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Mutable nullness information for a method's formal parameters and varargs array. For a varargs | ||
| * method, the nullability of individual arguments is represented in the last parameter position, | ||
| * while the nullability of the varargs array itself is represented separately. | ||
| */ | ||
| public final class MethodParameterNullness { | ||
|
|
||
| private final @Nullable Nullness[] parameterNullness; | ||
| private final boolean hasVarargsArrayNullness; | ||
| private @Nullable Nullness varargsArrayNullness; | ||
|
|
||
| private MethodParameterNullness(int parameterCount, boolean hasVarargsArrayNullness) { | ||
| this.parameterNullness = new Nullness[parameterCount]; | ||
| this.hasVarargsArrayNullness = hasVarargsArrayNullness; | ||
| } | ||
|
|
||
| public static MethodParameterNullness create(Symbol.MethodSymbol methodSymbol) { | ||
| return new MethodParameterNullness( | ||
| methodSymbol.getParameters().size(), methodSymbol.isVarArgs()); | ||
| } | ||
|
|
||
| public @Nullable Nullness getParameterNullness(int index) { | ||
| return parameterNullness[index]; | ||
| } | ||
|
|
||
| public void setParameterNullness(int index, @Nullable Nullness nullness) { | ||
| parameterNullness[index] = nullness; | ||
| } | ||
|
|
||
| public @Nullable Nullness getVarargsArrayNullness() { | ||
| checkHasVarargsArrayNullness(); | ||
| return varargsArrayNullness; | ||
| } | ||
|
|
||
| public void setVarargsArrayNullness(@Nullable Nullness nullness) { | ||
| checkHasVarargsArrayNullness(); | ||
| varargsArrayNullness = nullness; | ||
| } | ||
|
|
||
| private void checkHasVarargsArrayNullness() { | ||
| if (!hasVarargsArrayNullness) { | ||
| throw new IllegalStateException("No varargs array nullness slot for non-varargs method"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to allow using this class in the future to override deep nullability? E.g. allow stuff like overriding argument 1 of
foo(List<Bar> bars)to beList<@Nullable Bar>orList<? extends @Nullable Bar>or whatever? Obviously outside of the scope of this PR, but I am curious...We currently have a separate model from LibraryModels to set these kinds of annotations for third-party libraries / JDK method, right? (using astub(x)?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now this is handled by the
onOverrideMethodTypehandler method, see, e.g., here for library models:https://github.com/uber/NullAway/blob/7b5c9243f89a7a344025006942a0378500d2e954/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java#L453
It would be great to unify the two eventually, but it will also be painful given that we still need to handle declaration annotations and other legacy corner cases. Plus, all the original APIs didn't handle nested annotations, and that support has been tacked on for JSpecify mode, in a way that allows for JSpecify mode to be turned off. I think maybe when JSpecify mode is the default, or even better when there is only JSpecify mode for NullAway, we could think about cleaning things up into one handler method.