File: AssertParameterNullness.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 (31 lines) | stat: -rw-r--r-- 1,038 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
import org.checkerframework.checker.nullness.qual.*;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;

public class AssertParameterNullness {

    /** True iff both sequences are non-null and have the same length. */
    @EnsuresNonNullIf(
            result = true,
            expression = {"#1", "#2"})
    /* pure */ public static boolean sameLength(
            final boolean @Nullable [] seq1, final boolean @Nullable [] seq2) {
        if ((seq1 != null) && (seq2 != null) && seq1.length == seq2.length) {
            return true;
        }
        return false;
    }

    /* pure */ public static boolean pairwiseEqual(
            boolean @Nullable [] seq3, boolean @Nullable [] seq4) {
        if (sameLength(seq3, seq4)) {
            boolean b1 = seq3[0];
            boolean b2 = seq4[0];
        } else {
            // :: error: (accessing.nullable)
            boolean b1 = seq3[0];
            // :: error: (accessing.nullable)
            boolean b2 = seq4[0];
        }
        return true;
    }
}