NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

False-positive when dereferencing an inline-initialized field from constructor body

Open agrieve opened this issue 11 months ago • 4 comments

@NullMarked
class Foo {
    private @Nullable Object mArgs = new Object();

    Foo() {
        mArgs.getClass();
    }
}

Gives:

Foo.java:9: warning: [NullAway] dereferenced expression mArgs is @Nullable
        mArgs.getClass();
             ^
    (see http://t.uber.com/nullaway )

agrieve avatar Jan 28 '25 18:01 agrieve

I can reproduce this and I think we should handle it. It'll take a bit of time to do the implementation required.

msridhar avatar Jan 31 '25 21:01 msridhar

@agrieve getting back to this one after a while. How important is fixing this for you all? I have a tentative fix but I'm a bit concerned about performance overhead. But if it comes up a lot for you I can probably optimize it and get it in

msridhar avatar Oct 01 '25 14:10 msridhar

I haven't personally hit it since reporting it.

agrieve avatar Oct 01 '25 15:10 agrieve

Ok, since this just leads to false positives and it seems to come up rarely, I'm going to de-prioritize it for now. Happy to look again if someone else hits this very regularly.

msridhar avatar Oct 01 '25 17:10 msridhar