-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Unit Tests for @nullable annotations on array in JSpecify mode and modified behaviour.
- Loading branch information
1 parent
5355c7c
commit f1ba82a
Showing
4 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyArrayTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.uber.nullaway; | ||
|
||
import com.google.errorprone.CompilationTestHelper; | ||
import java.util.Arrays; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class NullAwayJSpecifyArrayTests extends NullAwayTestsBase { | ||
|
||
@Test | ||
public void ArrayTypeAnnotationDereference() { | ||
makeHelper() | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import org.jspecify.annotations.Nullable;", | ||
"class Test {", | ||
" static @Nullable Integer [] fizz = {1};", | ||
" static void foo() {", | ||
" // Ok since @Nullable annotations on type are ignored currently.", | ||
" // however, this should report an error eventually.", | ||
" int bar = fizz.length;", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void ArrayTypeAnnotationAssignment() { | ||
makeHelper() | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import org.jspecify.annotations.Nullable;", | ||
"class Test {", | ||
" Object foo = new Object();", | ||
" void m( @Nullable Integer [] bar) {", | ||
" // OK: @Nullable annotations on type are ignored currently.", | ||
" // however, this should report an error eventually.", | ||
" foo = bar;", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void ArrayElementAnnotationDereference() { | ||
makeHelper() | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import org.jspecify.annotations.Nullable;", | ||
"class Test {", | ||
" static String @Nullable [] fizz = {\"1\"};", | ||
" static void foo() {", | ||
" // BUG: Diagnostic contains: dereferenced expression fizz is @Nullable", | ||
" int bar = fizz[0].length();", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Ignore("We do not support annotations on array currently") | ||
@Test | ||
public void ArrayElementAnnotationAssignment() { | ||
makeHelper() | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import org.jspecify.annotations.Nullable;", | ||
"class Test {", | ||
" Object fizz = new Object();", | ||
" void m( @Nullable Integer [] foo) {", | ||
" // BUG: Diagnostic contains: dereferenced expression arr[0] is @Nullable", | ||
" int bar = foo[0];", | ||
" //valid assignment", | ||
" fizz = foo;", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
private CompilationTestHelper makeHelper() { | ||
return makeTestHelperWithArgs( | ||
Arrays.asList( | ||
"-XepOpt:NullAway:AnnotatedPackages=com.uber", "-XepOpt:NullAway:JSpecifyMode=true")); | ||
} | ||
} |