File: ArrayCreationChecks.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 (50 lines) | stat: -rw-r--r-- 1,689 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
// This test case is for issue 44: https://github.com/kelloggm/checker-framework/issues/44

import org.checkerframework.checker.index.qual.*;

class ArrayCreationChecks {

    void test1(@Positive int x, @Positive int y) {
        int[] newArray = new int[x + y];
        @IndexFor("newArray") int i = x;
        @IndexFor("newArray") int j = y;
    }

    void test2(@NonNegative int x, @Positive int y) {
        int[] newArray = new int[x + y];
        @IndexFor("newArray") int i = x;
        @IndexOrHigh("newArray") int j = y;
    }

    void test3(@NonNegative int x, @NonNegative int y) {
        int[] newArray = new int[x + y];
        @IndexOrHigh("newArray") int i = x;
        @IndexOrHigh("newArray") int j = y;
    }

    void test4(@GTENegativeOne int x, @NonNegative int y) {
        // :: error: (array.length.negative)
        int[] newArray = new int[x + y];
        @LTEqLengthOf("newArray") int i = x;
        // :: error: (assignment.type.incompatible)
        @IndexOrHigh("newArray") int j = y;
    }

    void test5(@GTENegativeOne int x, @GTENegativeOne int y) {
        // :: error: (array.length.negative)
        int[] newArray = new int[x + y];
        // :: error: (assignment.type.incompatible)
        @IndexOrHigh("newArray") int i = x;
        // :: error: (assignment.type.incompatible)
        @IndexOrHigh("newArray") int j = y;
    }

    void test6(int x, int y) {
        // :: error: (array.length.negative)
        int[] newArray = new int[x + y];
        // :: error: (assignment.type.incompatible)
        @IndexFor("newArray") int i = x;
        // :: error: (assignment.type.incompatible)
        @IndexOrHigh("newArray") int j = y;
    }
}