diff --git a/nullaway/src/main/java/com/uber/nullaway/Nullness.java b/nullaway/src/main/java/com/uber/nullaway/Nullness.java index a359b0d051..c86520c5a4 100644 --- a/nullaway/src/main/java/com/uber/nullaway/Nullness.java +++ b/nullaway/src/main/java/com/uber/nullaway/Nullness.java @@ -227,8 +227,6 @@ public static boolean paramHasNullableAnnotation( if (symbol.isVarArgs() && paramInd == symbol.getParameters().size() - 1 && !config.isLegacyAnnotationLocation()) { - // individual arguments passed in the varargs positions can be @Nullable if the array element - // type of the parameter is @Nullable return NullabilityUtil.nullableVarargsElementsForSourceOrBytecode( symbol.getParameters().get(paramInd), config); } else { @@ -270,8 +268,6 @@ public static boolean paramHasNonNullAnnotation( if (symbol.isVarArgs() && paramInd == symbol.getParameters().size() - 1 && !config.isLegacyAnnotationLocation()) { - // individual arguments passed in the varargs positions must be @NonNull if the array element - // type of the parameter is @NonNull return NullabilityUtil.nonnullVarargsElementsForSourceOrBytecode( symbol.getParameters().get(paramInd), config); } else { diff --git a/nullaway/src/test/java/com/uber/nullaway/VarargsTests.java b/nullaway/src/test/java/com/uber/nullaway/VarargsTests.java index 9bdea6c01f..ca66c10fd4 100644 --- a/nullaway/src/test/java/com/uber/nullaway/VarargsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/VarargsTests.java @@ -71,6 +71,7 @@ public void testNullableVarargs() { .doTest(); } + /** Test for a @Nullable declaration annotation on a varargs parameter defined in bytecode */ @Test public void nullableVarArgsFromBytecode() { defaultCompilationHelper @@ -532,6 +533,10 @@ public void testVarargsRestrictive() { .doTest(); } + /** + * Test for a restrictive @NonNull declaration annotation on a varargs parameter defined in + * bytecode + */ @Test public void testVarargsRestrictiveBytecodes() { makeTestHelperWithArgs( diff --git a/test-java-lib/src/main/java/com/uber/lib/unannotated/RestrictivelyAnnotatedVarargs.java b/test-java-lib/src/main/java/com/uber/lib/unannotated/RestrictivelyAnnotatedVarargs.java index 970fadaafb..4a80a0da6c 100644 --- a/test-java-lib/src/main/java/com/uber/lib/unannotated/RestrictivelyAnnotatedVarargs.java +++ b/test-java-lib/src/main/java/com/uber/lib/unannotated/RestrictivelyAnnotatedVarargs.java @@ -4,9 +4,5 @@ public class RestrictivelyAnnotatedVarargs { - public static void test(@Nonnull String... args) { - for (String arg : args) { - System.out.println(arg); - } - } + public static void test(@Nonnull String... args) {} }