| 1 |
import java.io.*; |
| 2 |
import java.util.Comparator; |
| 3 |
import java.util.HashSet; |
| 4 |
import java.util.Set; |
| 5 |
import org.checkerframework.checker.nullness.qual.*; |
| 6 |
import org.checkerframework.dataflow.qual.*; |
| 7 |
|
| 8 |
@org.checkerframework.framework.qual.DefaultQualifier(Nullable.class) |
| 9 |
public class GenericArgs { |
| 10 |
|
| 11 |
public @NonNull Set<@NonNull String> strings = new HashSet<>(); |
| 12 |
|
| 13 |
void test() { |
| 14 |
@NonNull HashSet<@NonNull String> s = new HashSet<>(); |
| 15 |
|
| 16 |
strings.addAll(s); |
| 17 |
strings.add("foo"); |
| 18 |
} |
| 19 |
|
| 20 |
static class X<@NonNull T extends @NonNull Object> { |
| 21 |
T value() { |
| 22 |
// :: error: (return.type.incompatible) |
| 23 |
return null; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public static void test2() { |
| 28 |
// :: error: (type.argument.type.incompatible) |
| 29 |
Object o = new X<Object>().value(); |
| 30 |
} |
| 31 |
|
| 32 |
static <@NonNull Z extends @NonNull Object> void test3(Z z) {} |
| 33 |
|
| 34 |
void test4() { |
| 35 |
// :: error: (type.argument.type.incompatible) |
| 36 |
GenericArgs.<@Nullable Object>test3(null); |
| 37 |
// :: error: (argument.type.incompatible) |
| 38 |
GenericArgs.<@NonNull Object>test3(null); |
| 39 |
} |
| 40 |
|
| 41 |
static class GenericConstructor { |
| 42 |
<@NonNull T extends @NonNull Object> GenericConstructor(T t) {} |
| 43 |
} |
| 44 |
|
| 45 |
void test5() { |
| 46 |
// :: error: (argument.type.incompatible) |
| 47 |
new <@NonNull String>GenericConstructor(null); |
| 48 |
} |
| 49 |
|
| 50 |
void testRecursiveDeclarations() { |
| 51 |
class MyComparator<@NonNull T extends @NonNull Comparable<T>> |
| 52 |
implements Comparator<T @NonNull []> { |
| 53 |
@Pure |
| 54 |
public int compare(T[] a, T[] b) { |
| 55 |
return 0; |
| 56 |
} |
| 57 |
} |
| 58 |
Comparator<@NonNull String @NonNull []> temp = new MyComparator<@NonNull String>(); |
| 59 |
} |
| 60 |
} |