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
Proposal: Understand Optional isPresent/isEmpty/isAbsent #274
Comments
I like this idea, and agree it's not far from what NullAway already does. Basically we'd want to model the presence state of Optionals and report errors on bad @lazaroclapp what do you think? I'm not sure if this would work best in a Handler or just as a core part of NullAway. Of course implementation would take some work so we'd need to figure out how that would get done 😄 |
@hzsweers @msridhar Definitely fits with the model, not sure how it will fit with the code, thought. My impression is that the change would be a bit more involved than what what can currently be done with a Handler, but I am not sure. Basically, a duplicate of the entire Tentatively assigning to self so I can take a look when I am back in Jan, but feel free to take a look at how hard this would be if you are interested in it and have enough time :) |
At least in JDK 8 the |
Added Optional Emptiness handler which does couple of things 1. on `optionalFoo.get()` hints that it can be Nullable. 2. on `optionalFoo.isPresent()` sets the `optionalFoo.get()` access path to Non-null. This allows ``` if (fooOptional.isPresent()) { fooOptional.get().bar(); // Implicitly understood to be safe } ``` and returns a warning if not implied safe. Fixes #274 Added unit tests Handler is gated by a configuration flag.
Right now NullAway can understand cases like AutoValue where
I propose adding support for an
Optional
analogue:I think this is a good fit for NullAway since
Optional
is Java 8/Guava's alternative tonull
in common cases, and has precedent for this kind of data flow awareness of "was null-checked already". This would just be a different flavor.The text was updated successfully, but these errors were encountered: