Support optional.orElse(null)
This will pass as non-null:
Optional.<Object>empty().orElse(null)
For example:
class Example {
void f(Object o) {}
void fails() {
f(null);
}
void passesButShouldnt() {
f(Optional.<Object>empty().orElse(null));
}
}
I would expect anything.orElse( ... something Nullable ...) to be inferred to be Nullable.
@lazaroclapp I think we could handle this with a @Contract annotation. Maybe we can do it as a library model?
@lazaroclapp I think we could handle this with a
@Contractannotation. Maybe we can do it as a library model?
Funny you should ask. I am about done with a PR that allows to encode the same semantics as @Contract(!null -> !null) as a library model ;)
@Garciat This has now been fixed in master, we will try to cut a new version of NullAway with the fix (and the Error Prone upgrade) soon.
Thanks! That was super quick 🙏