Debian Codegraph @

checker/tests/nullness/generics/NullableLUB.java

raw
1 import org.checkerframework.checker.nullness.qual.*;
2
3 /* Test case that illustrated an unsoundness in the unification of
4 * type variables with non-type variables. The error did not previously
5 * get raised, leading to a missed NPE.
6 */
7 // :: error: (initialization.fields.uninitialized)
8 public class NullableLUB<T extends @Nullable Object> {
9 T t;
10 @Nullable T nt;
11
12 T m(boolean b, T p) {
13 T r1 = b ? p : null;
14 nt = r1;
15 // :: error: (assignment.type.incompatible)
16 t = r1;
17 // :: error: (return.type.incompatible)
18 return r1;
19 }
20
21 public static void main(String[] args) {
22 new NullableLUB<@NonNull Object>().m(false, new Object()).toString();
23 }
24
25 T m2(boolean b, T p) {
26 T r1 = b ? null : p;
27 nt = r1;
28 // :: error: (assignment.type.incompatible)
29 t = r1;
30 // :: error: (return.type.incompatible)
31 return r1;
32 }
33 }