Skip to content

Commit 635ecd2

Browse files
authored
Add more bailouts for raw types (#1153)
Fixes #1151 The extra check in `CheckIdenticalNullabilityVisitor` is not needed to fix this bug but seemed like a prudent addition.
1 parent baf8f77 commit 635ecd2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
4444
return true;
4545
}
4646
// bail out of checking raw types for now
47-
if (rhsTypeAsSuper.isRaw()) {
47+
if (rhsTypeAsSuper.isRaw() || lhsType.isRaw()) {
4848
return true;
4949
}
5050
List<Type> lhsTypeArguments = lhsType.getTypeArguments();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ private static boolean identicalTypeParameterNullability(
504504
*/
505505
private static boolean subtypeParameterNullability(
506506
Type lhsType, Type rhsType, VisitorState state, Config config) {
507+
if (lhsType.isRaw()) {
508+
return true;
509+
}
507510
if (lhsType.getKind().equals(TypeKind.ARRAY) && rhsType.getKind().equals(TypeKind.ARRAY)) {
508511
// for array types we must allow covariance, i.e., an array of @NonNull references is a
509512
// subtype of an array of @Nullable references; see

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,26 @@ public void rawTypes() {
10221022
.doTest();
10231023
}
10241024

1025+
@Test
1026+
public void rawVarargsParam() {
1027+
makeHelper()
1028+
.addSourceLines(
1029+
"Foo.java",
1030+
"import org.jspecify.annotations.NullMarked;",
1031+
"import org.jspecify.annotations.Nullable;",
1032+
"@NullMarked",
1033+
"public class Foo {",
1034+
" public interface Supplier<T extends @Nullable Object> extends java.util.function.Supplier<T> {",
1035+
" }",
1036+
" public static void waitForAll(Runnable callback, Supplier... suppliers) {",
1037+
" }",
1038+
" public static void test(Supplier<Object> sup2) {",
1039+
" waitForAll(() -> {}, sup2);",
1040+
" }",
1041+
"}")
1042+
.doTest();
1043+
}
1044+
10251045
@Test
10261046
public void nestedGenericTypeAssignment() {
10271047
makeHelper()

0 commit comments

Comments
 (0)