File: FlowCompound.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (57 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
import org.checkerframework.checker.nullness.qual.*;

class FlowCompound {

    @org.checkerframework.dataflow.qual.Pure
    public boolean equals(@Nullable Object o) {
        return o != null && this.getClass() != o.getClass();
    }

    void test(@Nullable String s) {

        if (s == null || s.length() > 0) {
            // :: error: (assignment.type.incompatible)
            @NonNull String test = s;
        }

        String tmp;
        @NonNull String notNull;
        tmp = "hello";
        notNull = tmp;
        notNull = tmp = "hello";
    }

    public static boolean equal(@Nullable Object a, @Nullable Object b) {
        assert b != null : "suppress nullness";
        return a == b || (a != null && a.equals(b));
    }

    public static void testCompoundAssignmentWithString() {
        String s = "m";
        s += "n";
        s.toString();
    }

    public static void testCompoundAssignmentWithChar() {
        String s = "m";
        s += 'n';
        s.toString();
    }

    public static void testCompoundAssignWithNull() {
        String s = "m";
        s += null;
        s.toString();
    }

    public static void testPrimitiveArray() {
        int[] a = {0};
        a[0] += 2;
        System.out.println(a[0]);
    }

    public static void testPrimitive() {
        Integer i = 1;
        i -= 2;
    }
}