-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control flow analysis fails within a stream collector #934
Comments
Hi @wbadam I was able to reproduce this. Support for this kind of reasoning on streams is limited to particular constructs where we were confident the handling was correct. I think we could probably extend this to handle |
@msridhar After a quick search I've found a couple of similar cases:
There may be more that I couldn't immediately find, but these I reckon would cover most of our cases. |
Fixes #934 The key new thing with the support here is we have further nesting. Rather than a `map` method, where the relevant lambda is passed directly: ```java stream.filter(foo -> foo.bar != null).map(foo -> foo.bar.baz) ``` In this case we have a `collect` call, which gets as its argument the result of `Collectors.toMap`, and the relevant lambdas are passed to `toMap`: ```java stream .filter(foo -> foo.bar != null) .collect(Collectors.toMap(foo -> foo.bar.baz, foo -> foo.bar.other)) ``` Supporting this requires some new types of logic in our streams handler (particularly because there are multiple relevant lambdas for a single `collect` call). We do also handle anonymous inner classes.
FYI @wbadam this fix was part of the 0.10.25 release from today |
I think this may be the same as #332 which was closed recently.
NullAway is unable to infer nullity on a dereference made inside a stream collector.
In the example below,
streams1()
passes when the filter is added, and fails otherwise. Instreams2()
, there is a dereference warning forfoo.bar
even though the filter makes sure the value is non-null.NullAway version:
0.10.24
The text was updated successfully, but these errors were encountered: