Skip to content

Commit

Permalink
JSpecify: fix for crash with wildcard types (#1020)
Browse files Browse the repository at this point in the history
For now we just bail out; wildcard support will come later.

Fixes #1014
  • Loading branch information
msridhar authored Aug 18, 2024
1 parent b37f5f9 commit b20df77
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sun.tools.javac.code.Types;
import java.util.List;
import javax.lang.model.type.NullType;
import javax.lang.model.type.TypeKind;

/**
* Visitor that checks for identical nullability annotations at all nesting levels within two types.
Expand All @@ -23,6 +24,10 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
if (rhsType instanceof NullType || rhsType.isPrimitive()) {
return true;
}
if (rhsType.getKind().equals(TypeKind.WILDCARD)) {
// TODO Handle wildcard types
return true;
}
Types types = state.getTypes();
// The base type of rhsType may be a subtype of lhsType's base type. In such cases, we must
// compare lhsType against the supertype of rhsType with a matching base type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,28 @@ public void issue1008() {
.doTest();
}

@Test
public void issue1014() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"import java.util.function.Function;",
"class Test<R> {",
" public interface PropertyFunction<",
" T extends @Nullable Object, R extends @Nullable Object, E extends Exception>",
" extends Function<T, R> {",
" R _apply(T t) throws E;",
" }",
" @Nullable PropertyFunction<? super R, ? extends String, ? super Exception> stringFunc;",
" public void propertyString() {",
" var f = stringFunc;",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down

0 comments on commit b20df77

Please sign in to comment.