NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

Feature Request: Do not warn on assumeNonNull(nullUnmarkedThing)

Open agrieve opened this issue 5 months ago • 6 comments

E.g.:

 warning: [NullAway] passing known @NonNull parameter 'tabGroupModelFilter' to CastToNonNullMethod (org.chromium.build.NullUtil.assumeNonNull) at position 0. This method argument should only take values that NullAway considers @Nullable at the invocation site, but which are known not to be null at runtime.

The warning is great for values that are known to be non-null, but for values from methods annotated with @NullUnmarked, it would make migrations easier if these warnings would not show (e.g. you could incrementally fix them, and then remove @NullUnmarked at the end).

agrieve avatar Aug 08 '25 19:08 agrieve

This would take some work as we do not yet track an unknown nullness state. We may need to do so eventually for better JSpecify support. Possibly we could carve out something simpler to handle this case.

msridhar avatar Aug 08 '25 19:08 msridhar

@agrieve @msridhar Hello! I'm interested in working on this issue. Would it be possible for me to take it on and start working on it? Additionally, if there are any guidelines or specific points I should keep in mind while addressing this issue, I'd appreciate it if you could share them.

raccoonback avatar Aug 10 '25 15:08 raccoonback

Thanks for the offer @raccoonback!

Here is the code that emits this error:

https://github.com/uber/NullAway/blob/7b64688ae693825c350b31a20c9a3ba9bfdbdf89/nullaway/src/main/java/com/uber/nullaway/NullAway.java#L2059-L2078

The simplest change I can think of would be to check if the actual parameter actual is a call to an unmarked method, and if so, don't emit the error. Would this be helpful to you all @agrieve? It wouldn't handle the case where the result of the unmarked call is first stored in a local variable. That could also be handled but would require more work.

msridhar avatar Aug 12 '25 16:08 msridhar

I think that would actually address the majority of our warnings of this type :)

agrieve avatar Aug 13 '25 15:08 agrieve

@raccoonback are you able to take this one on?

msridhar avatar Aug 13 '25 21:08 msridhar

@msridhar Sure, I will take this issue and work on it.

raccoonback avatar Aug 14 '25 00:08 raccoonback