Skip to content

Commit 882ec59

Browse files
authored
Fix issue 1008 (#1009)
1 parent 5584291 commit 882ec59

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,14 @@ public static void compareGenericTypeParameterNullabilityForCall(
557557
(Type.ArrayType) formalParams.get(formalParams.size() - 1).type;
558558
Type varargsElementType = varargsArrayType.elemtype;
559559
for (int i = formalParams.size() - 1; i < actualParams.size(); i++) {
560-
Type actualParameter = getTreeType(actualParams.get(i), state);
561-
if (actualParameter != null) {
562-
if (!subtypeParameterNullability(varargsElementType, actualParameter, state)) {
560+
Type actualParameterType = getTreeType(actualParams.get(i), state);
561+
// If the actual parameter type is assignable to the varargs array type, then the call site
562+
// is passing the varargs directly in an array, and we should skip our check.
563+
if (actualParameterType != null
564+
&& !state.getTypes().isAssignable(actualParameterType, varargsArrayType)) {
565+
if (!subtypeParameterNullability(varargsElementType, actualParameterType, state)) {
563566
reportInvalidParametersNullabilityError(
564-
varargsElementType, actualParameter, actualParams.get(i), state, analysis);
567+
varargsElementType, actualParameterType, actualParams.get(i), state, analysis);
565568
}
566569
}
567570
}

nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,23 @@ public void boxInteger() {
18391839
.doTest();
18401840
}
18411841

1842+
@Test
1843+
public void issue1008() {
1844+
// testing for no crash
1845+
makeHelper()
1846+
.addSourceLines(
1847+
"EnumCombinations.java",
1848+
"package com.uber;",
1849+
"public class EnumCombinations {",
1850+
" public static void combinations(Class<? extends Enum<?>> first, Class<? extends Enum<?>>... others) {",
1851+
" }",
1852+
" public static void args(Class<? extends Enum<?>> first, Class<? extends Enum<?>>... others) {",
1853+
" combinations(first, others);",
1854+
" }",
1855+
"}")
1856+
.doTest();
1857+
}
1858+
18421859
private CompilationTestHelper makeHelper() {
18431860
return makeTestHelperWithArgs(
18441861
Arrays.asList(

0 commit comments

Comments
 (0)