Skip to content

Commit b20df77

Browse files
authored
JSpecify: fix for crash with wildcard types (#1020)
For now we just bail out; wildcard support will come later. Fixes #1014
1 parent b37f5f9 commit b20df77

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.sun.tools.javac.code.Types;
66
import java.util.List;
77
import javax.lang.model.type.NullType;
8+
import javax.lang.model.type.TypeKind;
89

910
/**
1011
* Visitor that checks for identical nullability annotations at all nesting levels within two types.
@@ -23,6 +24,10 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
2324
if (rhsType instanceof NullType || rhsType.isPrimitive()) {
2425
return true;
2526
}
27+
if (rhsType.getKind().equals(TypeKind.WILDCARD)) {
28+
// TODO Handle wildcard types
29+
return true;
30+
}
2631
Types types = state.getTypes();
2732
// The base type of rhsType may be a subtype of lhsType's base type. In such cases, we must
2833
// compare lhsType against the supertype of rhsType with a matching base type.

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

+22
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,28 @@ public void issue1008() {
18561856
.doTest();
18571857
}
18581858

1859+
@Test
1860+
public void issue1014() {
1861+
makeHelper()
1862+
.addSourceLines(
1863+
"Test.java",
1864+
"package com.uber;",
1865+
"import org.jspecify.annotations.Nullable;",
1866+
"import java.util.function.Function;",
1867+
"class Test<R> {",
1868+
" public interface PropertyFunction<",
1869+
" T extends @Nullable Object, R extends @Nullable Object, E extends Exception>",
1870+
" extends Function<T, R> {",
1871+
" R _apply(T t) throws E;",
1872+
" }",
1873+
" @Nullable PropertyFunction<? super R, ? extends String, ? super Exception> stringFunc;",
1874+
" public void propertyString() {",
1875+
" var f = stringFunc;",
1876+
" }",
1877+
"}")
1878+
.doTest();
1879+
}
1880+
18591881
private CompilationTestHelper makeHelper() {
18601882
return makeTestHelperWithArgs(
18611883
Arrays.asList(

0 commit comments

Comments
 (0)