File: Issue355.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 (58 lines) | stat: -rw-r--r-- 1,373 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
// Test case for Issue 355:
// https://github.com/typetools/checker-framework/issues/355

import java.util.List;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

class Issue355 {
    static <T extends @Nullable Object> @NonNull T checkNotNull(@Nullable T sample) {
        throw new RuntimeException();
    }

    void m(List<String> xs) {
        for (String x : checkNotNull(xs)) {}
    }
}

class Issue355b {
    static <T> T checkNotNull(T sample) {
        throw new RuntimeException();
    }

    void m(List<String> xs) {
        for (Object x : checkNotNull(xs)) {}
    }
}

class Issue355c {
    static <T> T checkNotNull(@NonNull T sample) {
        throw new RuntimeException();
    }

    void m(List<String> xs) {
        for (Object x : checkNotNull(xs)) {}
    }
}

class Issue355d {
    static <T> @Nullable T checkNotNull(@NonNull T sample) {
        throw new RuntimeException();
    }

    void m(List<String> xs) {
        // :: error: (iterating.over.nullable)
        for (Object x : checkNotNull(xs)) {}
    }
}

class Issue355e {
    static <T> @NonNull T checkNotNull(@NonNull T sample) {
        throw new RuntimeException();
    }

    void m(@Nullable List<String> xs) {
        // :: error: (argument.type.incompatible)
        for (Object x : checkNotNull(xs)) {}
    }
}