Skip to content

Commit

Permalink
Annotate firstNonNull as permitting nullable values for its second …
Browse files Browse the repository at this point in the history
…parameter.

It has permitted them at runtime since the beginning, and that's intentional. (This CL also adds a test, which somehow we didn't have for all these years? _And_ somehow the tests that we did have weren't open-sourced, so this CL open-sources them.) And based on testing, I can say: Many callers pass not only values whose static type is nullable but also whose _actual runtime value_ is `null`. I don't have my testing results handy anymore, so I don't have a real-world example to share right now, but you can imagine something like this:

```java
for (Key key : union(map1.keySet(), map2.keySet()) {
  Value value = firstNonNull(map1.get(key), map2.get(key));
}
```

RELNOTES=n/a
PiperOrigin-RevId: 531596646
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed May 12, 2023
1 parent b331769 commit 4aaebca
Show file tree
Hide file tree
Showing 4 changed files with 996 additions and 36 deletions.
Loading

0 comments on commit 4aaebca

Please sign in to comment.