NullAway
NullAway copied to clipboard
No error reported if receiver type argument is NonNull while method return type parameter is Nullable
@NullMarked
class Test {
private static class Inner<T extends @Nullable Object> {
Inner<@Nullable T> identity() { return this; }
}
Inner<Object> mThing = new Inner<Object>();
void foo() {
mThing = mThing.identity();
}
}
identity() returns Inner<@Nullable Object> and we are assigning that to a variable of type Inner<NonNull Object>, this is unsafe and should be reported by NullAway.
Note that the body of the identity method should not type check, as returning this won't always return an Inner with a @Nullable type argument. But this checking of generic classes is not yet supported by NullAway. Where I would expect an error is at the assignment to mThing inside foo.