| 1 |
import org.checkerframework.checker.nullness.qual.*; |
| 2 |
|
| 3 |
class GenericsBounds5 { |
| 4 |
class Collection1<E extends @Nullable Object> { |
| 5 |
public void add(E elt) { |
| 6 |
// This call is forbidden, because elt might be null. |
| 7 |
// :: error: (dereference.of.nullable) |
| 8 |
elt.hashCode(); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
<@Nullable F extends @Nullable Object> void addNull1(Collection1<F> l) { |
| 13 |
// This call is allowed, because F is definitely @Nullable. |
| 14 |
l.add(null); |
| 15 |
} |
| 16 |
|
| 17 |
// Effectively, this should be the same signature as above. |
| 18 |
// TODO: the type "@Nullable ?" is "@Nullable ? extends @NonNull Object", |
| 19 |
// with the wrong extends bound. |
| 20 |
void addNull2(Collection1<@Nullable ? extends @Nullable Object> l) { |
| 21 |
// This call has to pass, like above. |
| 22 |
l.add(null); |
| 23 |
} |
| 24 |
|
| 25 |
<@Nullable F extends @Nullable Object> void addNull3(Collection1<F> l, F p) { |
| 26 |
// This call is allowed, because F is definitely @Nullable. |
| 27 |
l.add(null); |
| 28 |
l.add(p); |
| 29 |
} |
| 30 |
|
| 31 |
// :: error: (assignment.type.incompatible) |
| 32 |
Collection1<@Nullable ? extends @Nullable Integer> f = new Collection1<@NonNull Integer>(); |
| 33 |
|
| 34 |
void bad(Collection1<@NonNull Integer> nnarg) { |
| 35 |
// These have to be forbidden, because f1 might refer to a |
| 36 |
// collection that has NonNull as type argument. |
| 37 |
// :: error: (type.argument.type.incompatible) |
| 38 |
addNull1(nnarg); |
| 39 |
|
| 40 |
// :: error: (argument.type.incompatible) |
| 41 |
addNull2(nnarg); |
| 42 |
|
| 43 |
// :: error: (type.argument.type.incompatible) |
| 44 |
addNull3(nnarg, Integer.valueOf(4)); |
| 45 |
} |
| 46 |
} |