-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
When using an AsyncLoadingCache where asyncLoad can return CompletableFuture(null), there is a potential for NullPointerException in AsyncWeigher.
Essentially, if the weigher does not null check the value, it can throw an NPE. This violates the documentation of Weigher, which has the value argument marked @NonNull.
The culprit for the Weigher case seems to be in the definition of AsyncWeigher, which delegates to the user-defined weigher whenever the future is done, without null-checking:
@Override
public int weigh(K key, CompletableFuture<V> future) {
return isReady(future) ? delegate.weigh(key, future.join()) : 0;
}Even though LocalAsyncLoadingCache.put(K, CompletableFuture<V>) attempts to check if the future contains null before passing it to the backing cache (and thus invoking the weigher), if the future finishes just after the initial check, but before the weigher is called, this NPE occurs. (See around this line.)