Skip to content
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

Avoid calling checkNotNull on nullable values except during actual precondition checks. #7090

Merged
1 commit merged into from
Mar 9, 2024

Conversation

copybara-service[bot]
Copy link
Contributor

Avoid calling checkNotNull on nullable values except during actual precondition checks.

It's not that we're not going to make such calls illegal, I promise :) I mean, we certainly aren't going to in general, but I am tempted for com.google.common, as discussed on cl/372346107 :) (It would have caught the problem of cl/612591080!) I'm testing what would happen if we did do it for com.google.common in case it shakes out any more bugs.

It does reveal that I didn't complete the cleanup of cl/612591080. And it reveals a few places where we'd normally use requireNonNull, since the checks aren't "preconditions" in the sense of "the caller did something wrong" (from cl/15376243 and cl/526930990). I've made those changes. (I would have made some more changes if I had tried to address more of com.google.common. But I stuck to the "main" packages, and I didn't even fix enough errors to see full results.)

Honestly, the more interesting thing that this exercise revealed was that there are more cases in which I'm especially sympathetic to calling checkNotNull on nullable values:

  • DummyProxy is making an InvocationHandler perform automatic precondition tests based on annotations on the interface it's implementing.
  • EqualsTester and Truth have permissive signatures because they're test utilities, as documented in cl/578260904 and discussed during the Truth CLs.

And the yet more interesting thing that it revealed is that we may want to use @NonNull here in the future, similar to what we've discussed in #6824.

RELNOTES=n/a

…precondition checks.

It's not that we're not going to make such calls illegal, I promise :) I mean, we certainly aren't going to _in general_, but I am tempted for `com.google.common`, as discussed on cl/372346107 :) (It would have caught the problem of cl/612591080!) I'm testing what would happen if we did do it for `com.google.common` in case it shakes out any more bugs.

It does reveal that I didn't complete the cleanup of cl/612591080. And it reveals a few places where we'd normally use `requireNonNull`, since the checks aren't "preconditions" in the sense of "the caller did something wrong" (from cl/15376243 and cl/526930990). I've made those changes. (I would have made some more changes if I had tried to address more of `com.google.common`. But I stuck to the "main" packages, and I didn't even fix enough errors to see full results.)

Honestly, the more interesting thing that this exercise revealed was that there are more cases in which I'm especially sympathetic to calling `checkNotNull` on nullable values:
- `DummyProxy` is making an `InvocationHandler` perform automatic precondition tests based on annotations on the interface it's implementing.
- `EqualsTester` and Truth have permissive signatures because they're test utilities, as documented in cl/578260904 and discussed during the Truth CLs.

And the yet more interesting thing that it revealed is that we may want to use `@NonNull` here in the future, similar to what we've discussed in #6824.

RELNOTES=n/a
PiperOrigin-RevId: 614074533
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant