Skip to content

Commit

Permalink
logic simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Sep 1, 2024
1 parent 6b622c7 commit 535af4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 3 additions & 3 deletions nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ public static boolean isArrayElementNullable(Symbol arraySymbol, Config config)
}
}
}
// In JSpecify mode, for varargs symbols we also consider the elements to be @Nullable if there
// is a @Nullable declaration annotation on the parameter
if (config.isJSpecifyMode() && (arraySymbol.flags() & Flags.VARARGS) != 0) {
// For varargs symbols we also consider the elements to be @Nullable if there is a @Nullable
// declaration annotation on the parameter
if ((arraySymbol.flags() & Flags.VARARGS) != 0) {
return Nullness.hasNullableDeclarationAnnotation(arraySymbol, config);
}
return false;
Expand Down
10 changes: 3 additions & 7 deletions nullaway/src/main/java/com/uber/nullaway/Nullness.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ public static boolean paramHasNullableAnnotation(
if (symbol.isVarArgs()
&& paramInd == symbol.getParameters().size() - 1
&& !config.isLegacyAnnotationLocation()) {
return individualVarargsParamsAreNullable(symbol.getParameters().get(paramInd), config);
// individual arguments passed in the varargs positions can be @Nullable if the array element
// type of the parameter is @Nullable
return NullabilityUtil.isArrayElementNullable(symbol.getParameters().get(paramInd), config);
} else {
return hasNullableAnnotation(
NullabilityUtil.getAllAnnotationsForParameter(symbol, paramInd, config), config);
Expand Down Expand Up @@ -276,12 +278,6 @@ public static boolean varargsArrayIsNullable(Symbol paramSymbol, Config config)
&& hasNullableDeclarationAnnotation(paramSymbol, config));
}

private static boolean individualVarargsParamsAreNullable(Symbol paramSymbol, Config config) {
// declaration annotation, or type-use annotation on the elements
return hasNullableDeclarationAnnotation(paramSymbol, config)
|| NullabilityUtil.isArrayElementNullable(paramSymbol, config);
}

/** Checks if the symbol has a {@code @Nullable} declaration annotation */
public static boolean hasNullableDeclarationAnnotation(Symbol symbol, Config config) {
return hasNullableAnnotation(symbol.getRawAttributes().stream(), config);
Expand Down

0 comments on commit 535af4f

Please sign in to comment.