| 1 |
import org.checkerframework.checker.nullness.qual.*; |
| 2 |
import org.checkerframework.framework.qual.DefaultQualifier; |
| 3 |
|
| 4 |
class WildcardSuper { |
| 5 |
|
| 6 |
void testWithSuper(Cell<? super @NonNull String> cell) { |
| 7 |
// TODO: Address comments. Since ? is explicitly lower bounded, I have made a judgment that |
| 8 |
// it should be implicitly upper bounded. |
| 9 |
// This is valid because the default upper bound is NonNull |
| 10 |
// :: error: (dereference.of.nullable) |
| 11 |
cell.get().toString(); |
| 12 |
} |
| 13 |
|
| 14 |
// TODO: THIS SHOULD JUST ISSUE A WARNING, WHY WOULD PEOPLE WANT TO WRITE CONTRADICTING BOUNDS? |
| 15 |
void testWithContradiction(Cell<? super @Nullable String> cell) { |
| 16 |
// This is actually valid, because it's a contradiction, b/c |
| 17 |
// the implicit upper bound is NonNull. |
| 18 |
// We are free to do anything, as the method is not callable. |
| 19 |
// TODO: test whether all calls of method fail. |
| 20 |
// :: error: (dereference.of.nullable) |
| 21 |
cell.get().toString(); |
| 22 |
} |
| 23 |
|
| 24 |
@DefaultQualifier(Nullable.class) |
| 25 |
void testWithImplicitNullable(@NonNull Cell<? super @NonNull String> cell) { |
| 26 |
// :: error: (dereference.of.nullable) |
| 27 |
cell.get().toString(); |
| 28 |
} |
| 29 |
|
| 30 |
void testWithExplicitNullable(Cell<@Nullable ? extends @Nullable String> cell) { |
| 31 |
// :: error: (dereference.of.nullable) |
| 32 |
cell.get().toString(); |
| 33 |
} |
| 34 |
|
| 35 |
void testWithDoubleNullable(Cell<@Nullable ? extends @Nullable String> cell) { |
| 36 |
// :: error: (dereference.of.nullable) |
| 37 |
cell.get().toString(); |
| 38 |
} |
| 39 |
|
| 40 |
class Cell<E extends @Nullable Object> { |
| 41 |
E get() { |
| 42 |
throw new RuntimeException(); |
| 43 |
} |
| 44 |
} |
| 45 |
} |