Skip to content

Commit

Permalink
Address nullness diagnostic.
Browse files Browse the repository at this point in the history
See
https://github.com/ben-manes/caffeine/actions/runs/12181931315/job/33979716621?pr=1806

```
Warning: /home/runner/work/caffeine/caffeine/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheLoader.java:233: warning: [NullAway] method returns @nullable, but superclass method com.github.benmanes.caffeine.cache.CacheLoader.load(K) returns @nonnull
      @OverRide public @nullable V load(K key) {
                                   ^
    (see http://t.uber.com/nullaway )
  Did you mean '@SuppressWarnings("NullAway") @OverRide public @nullable V load(K key) {'?
error: warnings found and -Werror specified
```
  • Loading branch information
cpovirk committed Dec 5, 2024
1 parent 461f020 commit 6ee7e20
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,20 @@ default CompletableFuture<? extends V> asyncReload(
* @throws NullPointerException if the mappingFunction is null
*/
@SuppressWarnings("FunctionalInterfaceClash")
static <K, V> CacheLoader<K, V> bulk(Function<? super Set<? extends K>,
? extends Map<? extends K, ? extends V>> mappingFunction) {
static <K, V extends @Nullable Object> CacheLoader<K, V> bulk(Function<? super Set<? extends K>,
? extends Map<? extends K, ? extends @NonNull V>> mappingFunction) {
requireNonNull(mappingFunction);
return new CacheLoader<>() {
@Override public @Nullable V load(K key) {
/*
* If the caller passes a mapping function that may ever return partial results, then calls to
* load() may return null. In that case, the caller should type the return value of bulk(...)
* as a CacheLoader<Foo, @Nullable Bar>, rather than a CacheLoader<Foo, Bar>.
*/
@SuppressWarnings("NullAway")
@Override public V load(K key) {
return loadAll(Set.of(key)).get(key);
}
@Override public Map<? extends K, ? extends V> loadAll(Set<? extends K> keys) {
@Override public Map<? extends K, ? extends @NonNull V> loadAll(Set<? extends K> keys) {
return mappingFunction.apply(keys);
}
};
Expand Down

0 comments on commit 6ee7e20

Please sign in to comment.