File: KeyForValidation.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 (123 lines) | stat: -rw-r--r-- 4,510 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.*;

@SuppressWarnings("fields.uninitialized")
public class KeyForValidation {

    // :: error: (expression.unparsable.type.invalid)
    static @KeyFor("this") Object f;

    @KeyFor("this") Object g;

    // :: error: (expression.unparsable.type.invalid)
    void m(@KeyFor("#0") Object p) {}

    // :: error: (expression.unparsable.type.invalid)
    void m2(@KeyFor("#4") Object p) {}

    // OK
    void m3(@KeyFor("#2") Object p, Map m) {}

    // TODO: index for a non-map
    void m4(@KeyFor("#1") Object p, Map m) {}

    // TODO: index with wrong type
    void m4(@KeyFor("#2") String p, Map<Integer, Integer> m) {}

    // :: error: (expression.unparsable.type.invalid)
    @KeyFor("INVALID") Object h;

    @KeyFor("f") Object i;

    void foo(Object p) {
        // :: error: (expression.unparsable.type.invalid)
        @KeyFor("ALSOBAD") Object j;

        @KeyFor("j") Object k;
        @KeyFor("f") Object l;

        @KeyFor("p") Object o;
    }

    // :: error: (expression.unparsable.type.invalid)
    void foo2(@KeyFor("ALSOBAD") Object o) {}
    // :: error: (expression.unparsable.type.invalid)
    void foo3(@KeyFor("ALSOBAD") Object[] o) {}
    // :: error: (expression.unparsable.type.invalid)
    void foo4(Map<@KeyFor("ALSOBAD") Object, Object> o) {}
    // :: error: (expression.unparsable.type.invalid)
    @KeyFor("ALSOBAD") Object[] foo5() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    @KeyFor("ALSOBAD") Object foo6() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    Map<@KeyFor("ALSOBAD") Object, Object> foo7() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    <@KeyFor("ALSOBAD") T> void foo8() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    <@KeyForBottom T extends @KeyFor("ALSOBAD") Object> void foo9() {}
    // :: error: (expression.unparsable.type.invalid)
    void foo10(@KeyFor("ALSOBAD") KeyForValidation this) {}

    // :: error: (expression.unparsable.type.invalid)
    public void test(Set<@KeyFor("BAD") String> keySet) {
        // :: error: (expression.unparsable.type.invalid)
        new ArrayList<@KeyFor("BAD") String>(keySet);
        // :: error: (expression.unparsable.type.invalid)
        List<@KeyFor("BAD") String> list = new ArrayList<>();

        // :: error: (expression.unparsable.type.invalid)
        for (@KeyFor("BAD") String s : list) {}
    }

    // Test static context.

    Object instanceField = new Object();

    // :: error: (expression.unparsable.type.invalid)
    static void bar2(@KeyFor("this.instanceField") Object o) {}
    // :: error: (expression.unparsable.type.invalid)
    static void bar3(@KeyFor("this.instanceField") Object[] o) {}
    // :: error: (expression.unparsable.type.invalid)
    static void bar4(Map<@KeyFor("this.instanceField") Object, Object> o) {}
    // :: error: (expression.unparsable.type.invalid)
    static @KeyFor("this.instanceField") Object[] bar5() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    static @KeyFor("this.instanceField") Object bar6() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    static Map<@KeyFor("this.instanceField") Object, Object> bar7() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    static <@KeyFor("this.instanceField") T> void bar8() {
        throw new RuntimeException();
    }
    // :: error: (expression.unparsable.type.invalid)
    static <@KeyForBottom T extends @KeyFor("this.instanceField") Object> void bar9() {}

    // :: error: (expression.unparsable.type.invalid)
    public static void test2(Set<@KeyFor("this.instanceField") String> keySet) {
        // :: error: (expression.unparsable.type.invalid)
        new ArrayList<@KeyFor("this.instanceField") String>(keySet);
        // :: error: (expression.unparsable.type.invalid)
        new ArrayList<@KeyFor("this.instanceField") String>();

        List<String> list = new ArrayList<>();
        // :: error: (enhancedfor.type.incompatible) :: error: (expression.unparsable.type.invalid)
        for (@KeyFor("this.instanceField") String s : list) {}
    }
}