File: Issue1214.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 (70 lines) | stat: -rw-r--r-- 1,934 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
58
59
60
61
62
63
64
65
66
67
68
69
70
// Test case for issue #1214:
// https://github.com/typetools/checker-framework/issues/1214

import org.checkerframework.common.value.qual.*;

public class Issue1214 {

    static void noException() {
        int n = 0;
        try {
        } catch (Exception e) {
            n = 1;
        }
        @IntVal(0) int ok = n;
    }

    static void arrayAccess(String[] array) {
        int n = 0;
        try {
            String s = array[0];
        } catch (NullPointerException e) {
            n = 1;
        } catch (ArrayIndexOutOfBoundsException e) {
            n = 2;
        } catch (Exception e) {
            n = 3;
        }
        @IntVal({0, 1, 2}) int ok = n;
        // :: error: (assignment.type.incompatible)
        @IntVal({0, 1}) int ng1 = n;
        // :: error: (assignment.type.incompatible)
        @IntVal({0, 2}) int ng2 = n;
        // :: error: (assignment.type.incompatible)
        @IntVal(0) int ng3 = n;
    }

    static void forArray(String[] array) {
        int n = 0;
        try {
            for (String s : array) ;
        } catch (NullPointerException e) {
            n = 1;
        } catch (ArrayIndexOutOfBoundsException e) {
            n = 2;
        } catch (Exception e) {
            n = 3;
        }
        @IntVal({0, 1}) int ok = n;
        // :: error: (assignment.type.incompatible)
        @IntVal(0) int ng = n;
    }

    static void forIterable(Iterable<String> itr) {
        int n = 0;
        try {
            for (String s : itr) ;
        } catch (NullPointerException e) {
            n = 1;
        } catch (Exception e) {
            n = 2;
        }
        @IntVal({0, 1, 2}) int ok = n;
        // :: error: (assignment.type.incompatible)
        @IntVal({0, 1}) int ng1 = n;
        // :: error: (assignment.type.incompatible)
        @IntVal({0, 2}) int ng2 = n;
        // :: error: (assignment.type.incompatible)
        @IntVal(0) int ng3 = n;
    }
}