Debian Codegraph @

checker/tests/initialization/fbc/SimpleFbc.java

raw
1 import org.checkerframework.checker.initialization.qual.Initialized;
2 import org.checkerframework.checker.initialization.qual.NotOnlyInitialized;
3 import org.checkerframework.checker.initialization.qual.UnknownInitialization;
4 import org.checkerframework.checker.nullness.qual.NonNull;
5 import org.checkerframework.checker.nullness.qual.Nullable;
6 import org.checkerframework.dataflow.qual.Pure;
7
8 public class SimpleFbc {
9
10 SimpleFbc f;
11 @NotOnlyInitialized SimpleFbc g;
12
13 @Pure
14 int pure() {
15 return 1;
16 }
17
18 // :: error: (initialization.fields.uninitialized)
19 public SimpleFbc(String arg) {}
20
21 void test() {
22 @NonNull String s = "234";
23
24 // :: error: (assignment.type.incompatible)
25 s = null;
26 System.out.println(s);
27 }
28
29 void test2(@UnknownInitialization @NonNull SimpleFbc t) {
30 // :: error: (assignment.type.incompatible)
31 @NonNull SimpleFbc a = t.f;
32 }
33
34 // check committed-only semantics for fields
35 void test3(@UnknownInitialization @NonNull SimpleFbc t) {
36 @Initialized @Nullable SimpleFbc a = t.f;
37
38 // :: error: (assignment.type.incompatible)
39 @Initialized @Nullable SimpleFbc b = t.g;
40 }
41
42 void simplestTestEver() {
43 @NonNull String a = "abc";
44
45 // :: error: (assignment.type.incompatible)
46 a = null;
47
48 // :: error: (assignment.type.incompatible)
49 @NonNull String b = null;
50 }
51
52 void anotherMethod() {
53 @Nullable String s = null;
54
55 @Initialized @Nullable String t = s;
56 }
57 }