diff options
author | Manu Sridharan <msridhar@gmail.com> | 2024-03-02 17:04:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-02 17:04:16 -0800 |
commit | a42b3a8b97a216ed75c324e10ab48a63052cc9d6 (patch) | |
tree | da260eb90e7ffb3a7eca6a817ec910bd977bd11c | |
parent | 28cc318c41db2941f34e23bbd8b91c58b1bab241 (diff) | |
download | nullaway-a42b3a8b97a216ed75c324e10ab48a63052cc9d6.tar.gz |
JSpecify: skip checking when type is primitive (#924)
Previously, NullAway would crash for the given tests when in JSpecify
mode.
-rw-r--r-- | nullaway/src/main/java/com/uber/nullaway/generics/CompareNullabilityVisitor.java | 2 | ||||
-rw-r--r-- | nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/CompareNullabilityVisitor.java b/nullaway/src/main/java/com/uber/nullaway/generics/CompareNullabilityVisitor.java index de86547..b26ad80 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/CompareNullabilityVisitor.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/CompareNullabilityVisitor.java @@ -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(); diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java index 0b7e99d..cfedaa3 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java @@ -1717,6 +1717,31 @@ public class NullAwayJSpecifyGenericsTests extends NullAwayTestsBase { .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( |