Skip to content

Commit

Permalink
JSpecify: fix crashes where declared parameter / return types were raw (
Browse files Browse the repository at this point in the history
#989)

We were lacking bailouts for these cases
  • Loading branch information
msridhar committed Jun 30, 2024
1 parent c2d253e commit 1488098
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ public static void checkTypeParameterNullnessForFunctionReturnType(
}

Type formalReturnType = methodSymbol.getReturnType();
if (formalReturnType.isRaw()) {
// bail out of any checking involving raw types for now
return;
}
Type returnExpressionType = getTreeType(retExpr, state);
if (formalReturnType != null && returnExpressionType != null) {
boolean isReturnTypeValid =
Expand Down Expand Up @@ -511,6 +515,10 @@ public static void compareGenericTypeParameterNullabilityForCall(
}
for (int i = 0; i < n; i++) {
Type formalParameter = formalParams.get(i).type;
if (formalParameter.isRaw()) {
// bail out of any checking involving raw types for now
return;
}
Type actualParameter = getTreeType(actualParams.get(i), state);
if (actualParameter != null) {
if (!subtypeParameterNullability(formalParameter, actualParameter, state)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,36 @@ public void testRawTypeReceiverCast() {
.doTest();
}

@Test
public void pseudoAssignmentWithRawDeclaredTypes() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" static class A<T> {",
" void foo(T n) {}",
" }",
" static class B {",
" static void bar(A a) {}",
" static void m1(A<?> a) {",
" bar(a);",
" }",
" static A m2(A<?> a) {",
" return a;",
" }",
" @Nullable A<?> field;",
" void m3(A<?> a) {",
" field = a;",
" A local = a;",
" local = a;",
" }",
" }",
"}")
.doTest();
}

@Test
public void testUseOfUnannotatedCode() {
makeHelper()
Expand Down

0 comments on commit 1488098

Please sign in to comment.