Skip to content

Commit

Permalink
Remove warning about @nullable var args (#296)
Browse files Browse the repository at this point in the history
Unfortunatelly, it is commong to have wrapper functions that take
@nullable var args and e.g. pass them immediately to a formatting/logging
third-party method that also takes @nullable var args safely.

Because of this, erroring out on `@Nullable T args...` can cause a worse
experience than simply letting the local array `args` be considered a
`@Nullable` array. I am not too happy with current error reporting after
reverting this change, but the alternative blocks too many valid method
declarations.
  • Loading branch information
lazaroclapp committed Apr 1, 2019
1 parent a724228 commit b99e4cf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
18 changes: 0 additions & 18 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Expand Up @@ -492,24 +492,6 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
return checkOverriding(closestOverriddenMethod, methodSymbol, null, state);
}
}
// Check that var args (if any) is @Nullable, as NullAway doesn't currently support this case
if (methodSymbol.isVarArgs()) {
VarSymbol varArgsSymbol =
methodSymbol.getParameters().get(methodSymbol.getParameters().size() - 1);
if (Nullness.hasNullableAnnotation(varArgsSymbol)) {
String message =
"NullAway doesn't currently support @Nullable VarArgs. "
+ "Consider removing the @Nullable annotation from "
+ varArgsSymbol.toString()
+ " in "
+ methodSymbol.toString()
+ " (this issue can cause other errors below, wherever the var args array is dereferenced)";
return errorBuilder.createErrorDescription(
new ErrorMessage(MessageTypes.NULLABLE_VARARGS_UNSUPPORTED, message),
state.getPath(),
buildDescription(tree));
}
}
return Description.NO_MATCH;
}

Expand Down
1 change: 0 additions & 1 deletion nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
Expand Up @@ -1715,7 +1715,6 @@ public void testNullableVarargs() {
"package com.uber;",
"import javax.annotation.Nullable;",
"public class Utilities {",
" // BUG: Diagnostic contains: NullAway doesn't currently support @Nullable VarArgs",
" public static String takesNullableVarargs(Object o, @Nullable Object... others) {",
" String s = o.toString() + \" \";",
" // BUG: Diagnostic contains: enhanced-for expression others is @Nullable",
Expand Down

0 comments on commit b99e4cf

Please sign in to comment.