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)) {}
}
}
|