Skip to content

Commit

Permalink
JSpecify: skip checking when type is primitive (#924)
Browse files Browse the repository at this point in the history
Previously, NullAway would crash for the given tests when in JSpecify
mode.
  • Loading branch information
msridhar authored Mar 3, 2024
1 parent 28cc318 commit a42b3a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CompareNullabilityVisitor extends Types.DefaultTypeVisitor<Boolean,

@Override
public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
if (rhsType instanceof NullType) {
if (rhsType instanceof NullType || rhsType.isPrimitive()) {
return true;
}
Types types = state.getTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,31 @@ public void passAnnotatedLambdaOrMethodRefToUnannotatedCode() {
.doTest();
}

@Test
public void boxInteger() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" static void testAssign(int i) {",
" // should not do any check here due to primitive type",
" Integer I = i;",
" }",
" static Integer testReturn(int i) {",
" // should not do any check here due to primitive type",
" return i;",
" }",
" static void takeInteger(Integer I) {}",
" static void testCall(int i) {",
" // should not do any check here due to primitive type",
" takeInteger(i);",
" }",
"}")
.doTest();
}

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

0 comments on commit a42b3a8

Please sign in to comment.