| 1 |
package nullness.generics; |
| 2 |
|
| 3 |
import org.checkerframework.checker.nullness.qual.*; |
| 4 |
|
| 5 |
@SuppressWarnings("initialization.fields.uninitialized") |
| 6 |
class GenericBoundsExplicit<@NonNull T extends @Nullable Object> { |
| 7 |
|
| 8 |
T t; |
| 9 |
|
| 10 |
public void method() { |
| 11 |
// :: error: (dereference.of.nullable) |
| 12 |
String str = t.toString(); |
| 13 |
} |
| 14 |
|
| 15 |
public static void doSomething() { |
| 16 |
final GenericBoundsExplicit<@Nullable String> b = |
| 17 |
new GenericBoundsExplicit<@Nullable String>(); |
| 18 |
b.method(); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
@SuppressWarnings("initialization.fields.uninitialized") |
| 23 |
class GenericBoundsExplicit2<@NonNull TT extends @Nullable Object> { |
| 24 |
@Nullable TT tt1; |
| 25 |
@NonNull TT tt2; |
| 26 |
TT tt3; |
| 27 |
|
| 28 |
public void context() { |
| 29 |
|
| 30 |
// :: error: (dereference.of.nullable) |
| 31 |
tt1.toString(); |
| 32 |
tt2.toString(); |
| 33 |
|
| 34 |
// :: error: (dereference.of.nullable) |
| 35 |
tt3.toString(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
@SuppressWarnings("initialization.fields.uninitialized") |
| 40 |
class GenericBoundsExplicit3<@NonNull TTT extends @NonNull Object> { |
| 41 |
@Nullable TTT ttt1; |
| 42 |
@NonNull TTT ttt2; |
| 43 |
TTT ttt3; |
| 44 |
|
| 45 |
public void context() { |
| 46 |
// :: error: (dereference.of.nullable) |
| 47 |
ttt1.toString(); |
| 48 |
ttt2.toString(); |
| 49 |
ttt3.toString(); |
| 50 |
} |
| 51 |
} |