-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid giving the result of loads a non-null type.
2542ca8 changed types like the return type of `Cache.get` to be non-null instead of unspecified. As discussed in #594, the types really "should" be nullable, but that is inconvenient for most users. When Caffeine was using Checker Framework annotations, it could use `@PolyNull` to give Checker Framework users the best of both worlds and give users of other tools (notably Kotlin) a convenient (if not fully strict) experience, since those tools viewed the types as having unspecified nullness (in Kotlin terms, "platform types"). Caffeine could still use `@PolyNull` today if you want to restore the Checker Framework dependency. (And maybe someday JSpecify will include its own version, as discussed in jspecify/jspecify#79.) But the important thing is that Caffeine _not_ affirmatively make the type be non-null. And that's what `@NullMarked` does. That would cause trouble for a number of Kotlin users in Google's codebase. So, to undo that, we can use `@NullUnmarked` (recognized by Kotlin as of 2.0.20) on the methods where we want to keep types unspecified. Then we can optionally use `@NonNull` annotations on the _other_ types in the API in order to still make those types non-null. Kotlin actually _still_ doesn't quite get the types right, thanks to https://youtrack.jetbrains.com/issue/KT-73658. But this PR at least annotates correctly (I hope :)), which may help other tools even today and which should help Kotlin eventually. If enough people run into the Kotlin bug in practice, then we could consider backing out even more nullness information: If we were to remove `@NullMarked` from `Cache`+`AsyncCache` and then potentially sprinkle in some `@NonNull` annotations to compensate, then we could still preserve at least some of the new information in those classes. And of course other classes can remain `@NullMarked`.
- Loading branch information
Showing
2 changed files
with
39 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters