Repository navigation
Update handling of annotations on varargs argument #1025
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
Changes from all commits
145f0e3
50862eb
fbd131e
db9c3b1
d25d350
a466b27
9f37626
c45b44c
3d086f3
e75c938
98b3d12
f32dd87
65dd597
c85fec1
0878e5b
91fe3fe
c524432
252e6c3
925265d
58ece61
4068568
fe92b7d
62a7df5
893fabe
fee21e4
71301a3
bc46f2e
6b622c7
535af4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,6 @@ | |
|
|
||
| import com.google.auto.service.AutoService; | ||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Verify; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMultimap; | ||
|
|
@@ -1705,8 +1704,9 @@ private Description handleInvocation( | |
| List<? extends ExpressionTree> actualParams) { | ||
| List<VarSymbol> formalParams = methodSymbol.getParameters(); | ||
|
|
||
| boolean varArgsMethod = methodSymbol.isVarArgs(); | ||
| if (formalParams.size() != actualParams.size() | ||
| && !methodSymbol.isVarArgs() | ||
| && !varArgsMethod | ||
| && !methodSymbol.isStatic() | ||
| && methodSymbol.isConstructor() | ||
| && methodSymbol.enclClass().isInner()) { | ||
|
|
@@ -1751,7 +1751,7 @@ private Description handleInvocation( | |
| } | ||
| if (config.isJSpecifyMode()) { | ||
| GenericsChecks.compareGenericTypeParameterNullabilityForCall( | ||
| formalParams, actualParams, methodSymbol.isVarArgs(), this, state); | ||
| formalParams, actualParams, varArgsMethod, this, state); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1764,30 +1764,55 @@ private Description handleInvocation( | |
| // NOTE: the case of an invocation on a possibly-null reference | ||
| // is handled by matchMemberSelect() | ||
| for (int argPos = 0; argPos < argumentPositionNullness.length; argPos++) { | ||
| if (!Objects.equals(Nullness.NONNULL, argumentPositionNullness[argPos])) { | ||
| boolean varargPosition = varArgsMethod && argPos == formalParams.size() - 1; | ||
| boolean argIsNonNull = Objects.equals(Nullness.NONNULL, argumentPositionNullness[argPos]); | ||
| if (!varargPosition && !argIsNonNull) { | ||
| continue; | ||
| } | ||
| ExpressionTree actual = null; | ||
| ExpressionTree actual; | ||
| boolean mayActualBeNull = false; | ||
| if (argPos == formalParams.size() - 1 && methodSymbol.isVarArgs()) { | ||
| if (varargPosition) { | ||
| // Check all vararg actual arguments for nullability | ||
| // This is the case where no actual parameter is passed for the var args parameter | ||
| // (i.e. it defaults to an empty array) | ||
| if (actualParams.size() <= argPos) { | ||
| continue; | ||
| } | ||
| for (ExpressionTree arg : actualParams.subList(argPos, actualParams.size())) { | ||
| actual = arg; | ||
| mayActualBeNull = mayBeNullExpr(state, actual); | ||
| if (mayActualBeNull) { | ||
| break; | ||
| actual = actualParams.get(argPos); | ||
| // check if the varargs arguments are being passed as an array | ||
| Type.ArrayType varargsArrayType = | ||
| (Type.ArrayType) formalParams.get(formalParams.size() - 1).type; | ||
| Type actualParameterType = ASTHelpers.getType(actual); | ||
| if (actualParameterType != null | ||
| && state.getTypes().isAssignable(actualParameterType, varargsArrayType) | ||
| && actualParams.size() == argPos + 1) { | ||
| // This is the case where an array is explicitly passed in the position of the var args | ||
| // parameter | ||
| // If varargs array itself is not @Nullable, cannot pass @Nullable array | ||
|
msridhar marked this conversation as resolved.
Resolved
|
||
| if (!Nullness.varargsArrayIsNullable(formalParams.get(argPos), config)) { | ||
| mayActualBeNull = mayBeNullExpr(state, actual); | ||
| } | ||
| } else { | ||
| // This is the case were varargs are being passed individually, as 1 or more actual | ||
| // arguments starting at the position of the var args formal. | ||
| // If the formal var args accepts `@Nullable`, then there is nothing for us to check. | ||
| if (!argIsNonNull) { | ||
| continue; | ||
| } | ||
| // TODO report all varargs errors in a single build; this code only reports the first | ||
| // error | ||
| for (ExpressionTree arg : actualParams.subList(argPos, actualParams.size())) { | ||
| actual = arg; | ||
| mayActualBeNull = mayBeNullExpr(state, actual); | ||
| if (mayActualBeNull) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| } else { // not the vararg position | ||
| actual = actualParams.get(argPos); | ||
| mayActualBeNull = mayBeNullExpr(state, actual); | ||
| } | ||
| // This statement should be unreachable without assigning actual beforehand: | ||
| Preconditions.checkNotNull(actual); | ||
|
Comment on lines
-1788
to
-1789
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still the case, right? Is just that now NullAway can prove this statically?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, |
||
| // make sure we are passing a non-null value | ||
| if (mayActualBeNull) { | ||
| String message = | ||
| "passing @Nullable parameter '" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.