File: LessThanLen.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (57 lines) | stat: -rw-r--r-- 2,005 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.index.qual.*;
import org.checkerframework.common.value.qual.MinLen;

public class LessThanLen {

    public static void m1() {
        int[] shorter = new int[5];
        int[] longer = new int[shorter.length * 2];
        for (int i = 0; i < shorter.length; i++) {
            longer[i] = shorter[i];
        }
    }

    public static void m2(int @MinLen(1) [] shorter) {
        int[] longer = new int[shorter.length * 2];
        for (int i = 0; i < shorter.length; i++) {
            longer[i] = shorter[i];
        }
    }

    public static void m3(int[] shorter) {
        int[] longer = new int[shorter.length + 1];
        for (int i = 0; i < shorter.length; i++) {
            longer[i] = shorter[i];
        }
    }

    public static void m4(int @MinLen(1) [] shorter) {
        int[] longer = new int[shorter.length * 1];
        // :: error: (assignment.type.incompatible)
        @LTLengthOf("longer") int x = shorter.length;
        @LTEqLengthOf("longer") int y = shorter.length;
    }

    public static void m5(int[] shorter) {
        // :: error: (array.length.negative)
        int[] longer = new int[shorter.length * -1];
        // :: error: (assignment.type.incompatible)
        @LTLengthOf("longer") int x = shorter.length;
        // :: error: (assignment.type.incompatible)
        @LTEqLengthOf("longer") int y = shorter.length;
    }

    public static void m6(int @MinLen(1) [] shorter) {
        int[] longer = new int[4 * shorter.length];
        // TODO: enable when https://github.com/kelloggm/checker-framework/issues/211 is fixed
        // // :: error: (assignment.type.incompatible)
        // @LTLengthOf("longer") int x = shorter.length;
        @LTEqLengthOf("longer") int y = shorter.length;
    }

    public static void m7(int @MinLen(1) [] shorter) {
        int[] longer = new int[4 * shorter.length];
        @LTLengthOf("longer") int x = shorter.length;
        @LTEqLengthOf("longer") int y = shorter.length;
    }
}