NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

No error reported if receiver type argument is NonNull while method return type parameter is Nullable

Open dhruv-agr opened this issue 8 months ago • 1 comments

@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.

dhruv-agr avatar Apr 20 '25 19:04 dhruv-agr

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.

msridhar avatar Apr 20 '25 20:04 msridhar