File: UncheckedMinLen.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 (45 lines) | stat: -rw-r--r-- 1,560 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
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.index.qual.Positive;
import org.checkerframework.common.value.qual.IntRange;
import org.checkerframework.common.value.qual.MinLen;

// test case for kelloggm#183: https://github.com/kelloggm/checker-framework/issues/183

public class UncheckedMinLen {
    void addToNonNegative(@NonNegative int l, Object v) {
        // :: error: (assignment.type.incompatible)
        Object @MinLen(100) [] o = new Object[l + 1];
        o[99] = v;
    }

    void addToPositive(@Positive int l, Object v) {
        // :: error: (assignment.type.incompatible)
        Object @MinLen(100) [] o = new Object[l + 1];
        o[99] = v;
    }

    void addToUnboundedIntRange(@IntRange(from = 0) int l, Object v) {
        // :: error: (assignment.type.incompatible)
        Object @MinLen(100) [] o = new Object[l + 1];
        o[99] = v;
    }

    // Similar code that correctly gives warnings
    void addToPositiveOK(@NonNegative int l, Object v) {
        Object[] o = new Object[l + 1];
        // :: error: (array.access.unsafe.high.constant)
        o[99] = v;
    }

    void addToBoundedIntRangeOK(@IntRange(from = 0, to = 1) int l, Object v) {
        // :: error: (assignment.type.incompatible)
        Object @MinLen(100) [] o = new Object[l + 1];
        o[99] = v;
    }

    void subtractFromPositiveOK(@Positive int l, Object v) {
        // :: error: (assignment.type.incompatible)
        Object @MinLen(100) [] o = new Object[l - 1];
        o[99] = v;
    }
}