-
Notifications
You must be signed in to change notification settings - Fork 296
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
Variable checked non-null outside a forEach
or Stream
lambda triggers an error
#941
Comments
@sdeleuze thanks for the report. In general we want to be careful with assumptions regarding when lambdas will execute. We already bake in knowledge regarding certain stream operators, and I think Is |
forEach
lambda triggers an error
I understand there is nuance here, so maybe let's focus on |
Would you be open to also make |
Hi @sdeleuze yes those other cases you mention make sense as well. As an FYI, I have an upcoming holiday and some other deadlines, so I will likely not get to looking at supporting these scenarios until after April 17 or so. |
forEach
lambda triggers an errorforEach
or Stream
lambda triggers an error
|
@sdeleuze one concern I have with |
Java |
@sdeleuze I put up #952 as an initial implementation to fix this issue. I'm still a bit unsure about the |
Thinking more here, and this is all fuzzy: the bad case for a Using extra nullability information inside @yuxincs @lazaroclapp if you have further thoughts here or disagree with the above reasoning please comment. |
I recall (@yuxincs can correct me) that for NilAway we had some analysis of when lambdas "escaped" the current function. Could we do something similar for streams here? Like, as far as I can tell there are four cases, from most to least conservative:
Even for (2) there are some caveats for lambda's and fields, but they are similar to our caveats about aliasing: E.g.
For (3), the space for potential errors grows just based on how far the lambda expression might be from the point it gets executed. How many of the cases we care about would be handled by just (1)? (The one in the example for the issue certainly would be, it's just that we currently don't uproot access paths for fields of |
@lazaroclapp I think ideally, I'd like to implement your case 1, and see if there are still annoying false positives in practice. You're right that this is the case our current stream handlers are designed to handle. I guess the easiest implementation of this might be to have a list T of stream terminal operations, and then check if there is an appropriate parent node of the lambda in the AST that is a call to a method in T? We'd have to create the T list but otherwise this may not be too hard to implement, though it will add some complexity and runtime overhead. I did some searching around, and I did find several cases where Anyway, for simplicity maybe let's just continue the discussion in #952 🙂 |
Thanks for working on this, looking forward leveraging it in Spring with the upcoming NullAway related release. |
@sdeleuze the fix for this issue is part of NullAway 0.10.26 which was just released |
The most common source of irrelevant errors we see in Spring Framework codebase with NullAway is this use case where the static analysis is not able to consider
this.resolvedDataSources
non-nullable in code found in lambdas:Such code generates the following error:
It is true that some lambda could be executed at a later point when the value has changes, but the fact that by default this is not consider as a valid use case generates a lot of irrelevant errors, and I would like to avoid to add an artificial check inside the lambda.
Could that be refined?
The text was updated successfully, but these errors were encountered: