File: ExampleUsage.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 (33 lines) | stat: -rw-r--r-- 865 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
public class ExampleUsage {
    /**
     * this class contains a set of test methods that are supposed to show how the lowerbound
     * checker should work in practice. They contain no annotations - the only test is whether or
     * not it alarms on particular code constructs that are or are not safe
     */
    void safe_loop_const() {
        int[] arr = new int[5];
        int k;
        for (int i = 0; i < 5; i++) {
            k = arr[i];
        }
    }

    void safe_loop_spooky() {
        int[] arr = new int[5];
        int k;
        for (int i = -1; i < 4; ) {
            i++;
            k = arr[i];
        }
    }

    void obviously_unsafe_loop() {
        int[] arr = new int[5];
        int k;
        for (int i = -1; i < 5; i++) {
            // :: error: (array.access.unsafe.low)
            k = arr[i];
        }
    }
}
// a comment