Debian Codegraph @

checker/tests/nullness/java8/lambda/FinalLocalVariables.java

raw
1 // Test enclosing final local variables
2
3 import org.checkerframework.checker.nullness.qual.*;
4
5 interface FunctionLE<T extends @Nullable Object, R> {
6 R apply(T t);
7 }
8
9 class LambdaEnclosing {
10
11 // Test static initializer
12 static {
13 String local1 = "";
14 String local2 = null;
15 FunctionLE<String, String> f0 =
16 s -> {
17 local1.toString();
18 // :: error: (dereference.of.nullable)
19 local2.toString();
20 return "";
21 };
22 }
23
24 // Test instance initializer
25 {
26 String local1 = "";
27 String local2 = null;
28 FunctionLE<String, String> f0 =
29 s -> {
30 local1.toString();
31 // :: error: (dereference.of.nullable)
32 local2.toString();
33 return "";
34 };
35 }
36
37 FunctionLE<String, String> functionField =
38 s -> {
39 String local1 = "";
40 String local2 = null;
41 FunctionLE<String, String> f0 =
42 s2 -> {
43 local1.toString();
44 // :: error: (dereference.of.nullable)
45 local2.toString();
46 return "";
47 };
48 return "";
49 };
50
51 void context() {
52 String local1 = "";
53 String local2 = null;
54
55 FunctionLE<String, String> f1 =
56 s -> {
57 local1.toString();
58 // :: error: (dereference.of.nullable)
59 local2.toString();
60 class Inner {
61
62 void context2() {
63 String local3 = "";
64 String local4 = null;
65
66 FunctionLE<String, String> f2 =
67 s2 -> {
68 local1.toString();
69 local2.toString();
70 local3.toString();
71 // :: error: (dereference.of.nullable)
72 local4.toString();
73
74 return "";
75 };
76 }
77 }
78
79 new Object() {
80
81 @Override()
82 public String toString() {
83 String local3 = "";
84 String local4 = null;
85
86 FunctionLE<String, String> f2 =
87 s2 -> {
88 local1.toString();
89 local2.toString();
90 local3.toString();
91 // :: error: (dereference.of.nullable)
92 local4.toString();
93
94 return "";
95 };
96 return "";
97 }
98 }.toString();
99
100 return "";
101 };
102 }
103 }