diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java index d1100af4bd..4beae50616 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java @@ -557,11 +557,14 @@ public static void compareGenericTypeParameterNullabilityForCall( (Type.ArrayType) formalParams.get(formalParams.size() - 1).type; Type varargsElementType = varargsArrayType.elemtype; for (int i = formalParams.size() - 1; i < actualParams.size(); i++) { - Type actualParameter = getTreeType(actualParams.get(i), state); - if (actualParameter != null) { - if (!subtypeParameterNullability(varargsElementType, actualParameter, state)) { + Type actualParameterType = getTreeType(actualParams.get(i), state); + // If the actual parameter type is assignable to the varargs array type, then the call site + // is passing the varargs directly in an array, and we should skip our check. + if (actualParameterType != null + && !state.getTypes().isAssignable(actualParameterType, varargsArrayType)) { + if (!subtypeParameterNullability(varargsElementType, actualParameterType, state)) { reportInvalidParametersNullabilityError( - varargsElementType, actualParameter, actualParams.get(i), state, analysis); + varargsElementType, actualParameterType, actualParams.get(i), state, analysis); } } } diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java index 10736da214..2a662b55a5 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -1839,6 +1839,23 @@ public void boxInteger() { .doTest(); } + @Test + public void issue1008() { + // testing for no crash + makeHelper() + .addSourceLines( + "EnumCombinations.java", + "package com.uber;", + "public class EnumCombinations {", + " public static void combinations(Class> first, Class>... others) {", + " }", + " public static void args(Class> first, Class>... others) {", + " combinations(first, others);", + " }", + "}") + .doTest(); + } + private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList(