/
InstanceOfBindingTests.java
47 lines (41 loc) · 1.4 KB
/
InstanceOfBindingTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.uber.nullaway.jdk17;
import com.google.errorprone.CompilationTestHelper;
import com.uber.nullaway.NullAway;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class InstanceOfBindingTests {
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
private CompilationTestHelper defaultCompilationHelper;
@Before
public void setup() {
defaultCompilationHelper =
CompilationTestHelper.newInstance(NullAway.class, getClass())
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber"));
}
@Test
public void testInstanceOfBinding() {
defaultCompilationHelper
.addSourceLines(
"InstanceOfBinding.java",
"package com.uber;",
"import javax.annotation.Nullable;",
"class InstanceOfBinding {",
" public void testInstanceOfBinding(@Nullable Object o) {",
" if (o instanceof String s) {",
" s.toString();",
" o.toString();",
" }",
" // BUG: Diagnostic contains: dereferenced expression o",
" o.toString();",
" }",
"}")
.doTest();
}
}