diff --git a/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/BasicCache.java b/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/BasicCache.java index 22eaf1448b..d65f20dcc8 100644 --- a/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/BasicCache.java +++ b/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/BasicCache.java @@ -15,7 +15,6 @@ */ package com.github.benmanes.caffeine.cache; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -26,13 +25,13 @@ public interface BasicCache { /** Returns the value stored in the cache, or null if not present. */ - @Nullable V get(@NonNull K key); + @Nullable V get(K key); /** Stores the value into the cache, replacing an existing mapping if present. */ - void put(@NonNull K key, @NonNull V value); + void put(K key, V value); /** Removes the entry from the cache, if present. */ - void remove(@NonNull K key); + void remove(K key); /** Invalidates all entries from the cache. */ void clear(); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java index 19571ed2ce..ce4b0135de 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCache.java @@ -23,7 +23,6 @@ import java.util.function.BiFunction; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -50,7 +49,7 @@ public interface AsyncCache { * @throws NullPointerException if the specified key is null */ @Nullable - CompletableFuture getIfPresent(@NonNull K key); + CompletableFuture getIfPresent(K key); /** * Returns the future associated with {@code key} in this cache, obtaining that value from @@ -70,9 +69,7 @@ public interface AsyncCache { * @return the current (existing or computed) future value associated with the specified key * @throws NullPointerException if the specified key or mappingFunction is null */ - @NonNull - CompletableFuture get(@NonNull K key, - @NonNull Function mappingFunction); + CompletableFuture get(K key, Function mappingFunction); /** * Returns the future associated with {@code key} in this cache, obtaining that value from @@ -95,9 +92,8 @@ CompletableFuture get(@NonNull K key, * @throws RuntimeException or Error if the mappingFunction does when constructing the future, * in which case the mapping is left unestablished */ - @NonNull - CompletableFuture get(@NonNull K key, - @NonNull BiFunction> mappingFunction); + CompletableFuture get(K key, + BiFunction> mappingFunction); /** * Returns the future of a map of the values associated with {@code keys}, creating or retrieving @@ -122,9 +118,8 @@ CompletableFuture get(@NonNull K key, * @throws RuntimeException or Error if the mappingFunction does so, in which case the mapping is * left unestablished */ - @NonNull - CompletableFuture> getAll(@NonNull Iterable keys, - @NonNull Function, @NonNull Map> mappingFunction); + CompletableFuture> getAll(Iterable keys, + Function, Map> mappingFunction); /** * Returns the future of a map of the values associated with {@code keys}, creating or retrieving @@ -149,9 +144,8 @@ CompletableFuture> getAll(@NonNull Iterable keys * @throws RuntimeException or Error if the mappingFunction does so, in which case the mapping is * left unestablished */ - @NonNull - CompletableFuture> getAll(@NonNull Iterable keys, - @NonNull BiFunction, Executor, CompletableFuture>> mappingFunction); + CompletableFuture> getAll(Iterable keys, + BiFunction, Executor, CompletableFuture>> mappingFunction); /** * Associates {@code value} with {@code key} in this cache. If the cache previously contained a @@ -165,7 +159,7 @@ CompletableFuture> getAll(@NonNull Iterable keys * @param valueFuture value to be associated with the specified key * @throws NullPointerException if the specified key or value is null */ - void put(@NonNull K key, @NonNull CompletableFuture valueFuture); + void put(K key, CompletableFuture valueFuture); /** * Returns a view of the entries stored in this cache as a thread-safe map. Modifications made to @@ -182,8 +176,7 @@ CompletableFuture> getAll(@NonNull Iterable keys * * @return a thread-safe view of this cache supporting all of the optional {@link Map} operations */ - @NonNull - ConcurrentMap<@NonNull K, @NonNull CompletableFuture> asMap(); + ConcurrentMap> asMap(); /** * Returns a view of the entries stored in this cache as a synchronous {@link Cache}. A mapping is @@ -193,6 +186,5 @@ CompletableFuture> getAll(@NonNull Iterable keys * * @return a thread-safe synchronous view of this cache */ - @NonNull Cache synchronous(); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCacheLoader.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCacheLoader.java index a3665d601e..ae5e09aa47 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCacheLoader.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncCacheLoader.java @@ -24,8 +24,6 @@ import java.util.function.BiFunction; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * Computes or retrieves values asynchronously, based on a key, for use in populating a * {@link AsyncLoadingCache}. @@ -57,8 +55,7 @@ public interface AsyncCacheLoader { * treated like any other {@code Exception} in all respects except that, when it is * caught, the thread's interrupt status is set */ - @NonNull - CompletableFuture asyncLoad(@NonNull K key, @NonNull Executor executor) throws Exception; + CompletableFuture asyncLoad(K key, Executor executor) throws Exception; /** * Asynchronously computes or retrieves the values corresponding to {@code keys}. This method is @@ -82,9 +79,8 @@ public interface AsyncCacheLoader { * treated like any other {@code Exception} in all respects except that, when it is * caught, the thread's interrupt status is set */ - @NonNull - default CompletableFuture> asyncLoadAll( - @NonNull Set keys, @NonNull Executor executor) throws Exception { + default CompletableFuture> asyncLoadAll( + Set keys, Executor executor) throws Exception { throw new UnsupportedOperationException(); } @@ -106,9 +102,7 @@ public interface AsyncCacheLoader { * treated like any other {@code Exception} in all respects except that, when it is * caught, the thread's interrupt status is set */ - @NonNull - default CompletableFuture asyncReload( - @NonNull K key, @NonNull V oldValue, @NonNull Executor executor) throws Exception { + default CompletableFuture asyncReload(K key, V oldValue, Executor executor) throws Exception { return asyncLoad(key, executor); } @@ -128,7 +122,6 @@ default CompletableFuture asyncReload( * @return an asynchronous cache loader that delegates to the supplied {@code mappingFunction} * @throws NullPointerException if the mappingFunction is null */ - @NonNull static AsyncCacheLoader bulk(Function, Map> mappingFunction) { return CacheLoader.bulk(mappingFunction); } @@ -149,7 +142,6 @@ static AsyncCacheLoader bulk(Function, Map> * @return an asynchronous cache loader that delegates to the supplied {@code mappingFunction} * @throws NullPointerException if the mappingFunction is null */ - @NonNull static AsyncCacheLoader bulk( BiFunction, Executor, CompletableFuture>> mappingFunction) { requireNonNull(mappingFunction); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncLoadingCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncLoadingCache.java index 68c50a989e..4e1110e855 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncLoadingCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/AsyncLoadingCache.java @@ -18,8 +18,6 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * A semi-persistent mapping from keys to values. Values are automatically loaded by the cache * asynchronously, and are stored in the cache until either evicted or manually invalidated. @@ -49,8 +47,7 @@ public interface AsyncLoadingCache extends AsyncCache { * @throws RuntimeException or Error if the {@link AsyncCacheLoader} does when constructing the * future, in which case the mapping is left unestablished */ - @NonNull - CompletableFuture get(@NonNull K key); + CompletableFuture get(K key); /** * Returns the future of a map of the values associated with {@code keys}, creating or retrieving @@ -78,8 +75,7 @@ public interface AsyncLoadingCache extends AsyncCache { * {@link AsyncCacheLoader#asyncLoadAll} returns {@code null}, or fails when constructing * the future, in which case the mapping is left unestablished */ - @NonNull - CompletableFuture> getAll(@NonNull Iterable keys); + CompletableFuture> getAll(Iterable keys); /** * Returns a view of the entries stored in this cache as a synchronous {@link LoadingCache}. A @@ -89,7 +85,6 @@ public interface AsyncLoadingCache extends AsyncCache { * * @return a thread-safe synchronous view of this cache */ - @NonNull @Override LoadingCache synchronous(); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java index 68b1cc2d3d..8adf9dab65 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java @@ -70,7 +70,6 @@ import java.util.function.Predicate; import java.util.function.Supplier; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.Async.AsyncExpiry; @@ -752,13 +751,13 @@ void evictFromMain(int candidates) { K victimKey = victim.getKey(); K candidateKey = candidate.getKey(); if (victimKey == null) { - @NonNull Node evict = victim; + Node evict = victim; victim = victim.getNextInAccessOrder(); evictEntry(evict, RemovalCause.COLLECTED, 0L); continue; } else if (candidateKey == null) { candidates--; - @NonNull Node evict = candidate; + Node evict = candidate; candidate = candidate.getPreviousInAccessOrder(); evictEntry(evict, RemovalCause.COLLECTED, 0L); continue; @@ -3524,7 +3523,7 @@ final class BoundedEviction implements Eviction { @Override public boolean isWeighted() { return isWeighted; } - @Override public OptionalInt weightOf(@NonNull K key) { + @Override public OptionalInt weightOf(K key) { requireNonNull(key); if (!isWeighted) { return OptionalInt.empty(); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Buffer.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Buffer.java index 221f91ff1e..ba497e8c9a 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Buffer.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Buffer.java @@ -17,8 +17,6 @@ import java.util.function.Consumer; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * A multiple-producer / single-consumer buffer that rejects new elements if it is full or * fails spuriously due to contention. Unlike a queue and stack, a buffer does not guarantee an @@ -50,7 +48,7 @@ static Buffer disabled() { * @param e the element to add * @return {@code 1} if the buffer is full, {@code -1} if the CAS failed, or {@code 0} if added */ - int offer(@NonNull E e); + int offer(E e); /** * Drains the buffer, sending each element to the consumer for processing. The caller must ensure @@ -58,7 +56,7 @@ static Buffer disabled() { * * @param consumer the action to perform on each element */ - void drainTo(@NonNull Consumer consumer); + void drainTo(Consumer consumer); /** * Returns the number of elements residing in the buffer. diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java index ce80c14cc9..897ceffce9 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Cache.java @@ -21,8 +21,8 @@ import java.util.function.Function; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.checker.nullness.qual.PolyNull; import com.github.benmanes.caffeine.cache.stats.CacheStats; @@ -50,7 +50,7 @@ public interface Cache { * @throws NullPointerException if the specified key is null */ @Nullable - V getIfPresent(@NonNull K key); + V getIfPresent(K key); /** * Returns the value associated with the {@code key} in this cache, obtaining that value from the @@ -77,8 +77,8 @@ public interface Cache { * @throws RuntimeException or Error if the mappingFunction does so, in which case the mapping is * left unestablished */ - @Nullable - V get(@NonNull K key, @NonNull Function mappingFunction); + @PolyNull + V get(K key, Function mappingFunction); /** * Returns a map of the values associated with the {@code keys} in this cache. The returned map @@ -91,8 +91,7 @@ public interface Cache { * @return the unmodifiable mapping of keys to values for the specified keys found in this cache * @throws NullPointerException if the specified collection is null or contains a null element */ - @NonNull - Map<@NonNull K, @NonNull V> getAllPresent(@NonNull Iterable keys); + Map getAllPresent(Iterable keys); /** * Returns a map of the values associated with the {@code keys}, creating or retrieving those @@ -118,9 +117,8 @@ public interface Cache { * @throws RuntimeException or Error if the mappingFunction does so, in which case the mapping is * left unestablished */ - @NonNull - Map getAll(@NonNull Iterable keys, - @NonNull Function, @NonNull Map> mappingFunction); + Map getAll(Iterable keys, + Function, Map> mappingFunction); /** * Associates the {@code value} with the {@code key} in this cache. If the cache previously @@ -134,7 +132,7 @@ Map getAll(@NonNull Iterable keys, * @param value value to be associated with the specified key * @throws NullPointerException if the specified key or value is null */ - void put(@NonNull K key, @NonNull V value); + void put(K key, V value); /** * Copies all of the mappings from the specified map to the cache. The effect of this call is @@ -146,7 +144,7 @@ Map getAll(@NonNull Iterable keys, * @throws NullPointerException if the specified map is null or the specified map contains null * keys or values */ - void putAll(@NonNull Map map); + void putAll(Map map); /** * Discards any cached value for the {@code key}. The behavior of this operation is undefined for @@ -155,7 +153,7 @@ Map getAll(@NonNull Iterable keys, * @param key the key whose mapping is to be removed from the cache * @throws NullPointerException if the specified key is null */ - void invalidate(@NonNull K key); + void invalidate(K key); /** * Discards any cached values for the {@code keys}. The behavior of this operation is undefined @@ -164,7 +162,7 @@ Map getAll(@NonNull Iterable keys, * @param keys the keys whose associated values are to be removed * @throws NullPointerException if the specified collection is null or contains a null element */ - void invalidateAll(@NonNull Iterable keys); + void invalidateAll(Iterable keys); /** * Discards all entries in the cache. The behavior of this operation is undefined for an entry @@ -192,7 +190,6 @@ Map getAll(@NonNull Iterable keys, * * @return the current snapshot of the statistics of this cache */ - @NonNull CacheStats stats(); /** @@ -210,8 +207,7 @@ Map getAll(@NonNull Iterable keys, * * @return a thread-safe view of this cache supporting all of the optional {@link Map} operations */ - @NonNull - ConcurrentMap<@NonNull K, @NonNull V> asMap(); + ConcurrentMap asMap(); /** * Performs any pending maintenance operations needed by the cache. Exactly which activities are @@ -226,6 +222,5 @@ Map getAll(@NonNull Iterable keys, * * @return access to inspect and perform advanced operations based on the cache's characteristics */ - @NonNull Policy policy(); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheLoader.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheLoader.java index 9420e68165..984d8002e6 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheLoader.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheLoader.java @@ -24,7 +24,6 @@ import java.util.concurrent.Executor; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -59,7 +58,7 @@ public interface CacheLoader extends AsyncCacheLoader { * caught, the thread's interrupt status is set */ @Nullable - V load(@NonNull K key) throws Exception; + V load(K key) throws Exception; /** * Computes or retrieves the values corresponding to {@code keys}. This method is called by @@ -84,9 +83,7 @@ public interface CacheLoader extends AsyncCacheLoader { * treated like any other {@code Exception} in all respects except that, when it is * caught, the thread's interrupt status is set */ - @NonNull - default Map<@NonNull K, @NonNull V> loadAll( - @NonNull Set keys) throws Exception { + default Map loadAll(Set keys) throws Exception { throw new UnsupportedOperationException(); } @@ -97,8 +94,8 @@ public interface CacheLoader extends AsyncCacheLoader { * @param executor the executor that asynchronously loads the entry * @return the future value associated with {@code key} */ - @Override @NonNull - default CompletableFuture asyncLoad(@NonNull K key, @NonNull Executor executor) { + @Override + default CompletableFuture asyncLoad(K key, Executor executor) { requireNonNull(key); requireNonNull(executor); return CompletableFuture.supplyAsync(() -> { @@ -130,9 +127,8 @@ default CompletableFuture asyncLoad(@NonNull K key, @NonNull Executor executo * @return a future containing the map from each key in {@code keys} to the value associated with * that key; may not contain null values */ - @Override @NonNull - default CompletableFuture> asyncLoadAll( - @NonNull Set keys, @NonNull Executor executor) { + @Override + default CompletableFuture> asyncLoadAll(Set keys, Executor executor) { requireNonNull(keys); requireNonNull(executor); return CompletableFuture.supplyAsync(() -> { @@ -164,7 +160,7 @@ default CompletableFuture asyncLoad(@NonNull K key, @NonNull Executor executo * caught, the thread's interrupt status is set */ @Nullable - default V reload(@NonNull K key, @NonNull V oldValue) throws Exception { + default V reload(K key, V oldValue) throws Exception { return load(key); } @@ -182,9 +178,8 @@ default V reload(@NonNull K key, @NonNull V oldValue) throws Exception { * @return a future containing the new value associated with {@code key}, or containing * {@code null} if the mapping is to be removed */ - @Override @NonNull - default CompletableFuture asyncReload( - @NonNull K key, @NonNull V oldValue, @NonNull Executor executor) throws Exception { + @Override + default CompletableFuture asyncReload(K key, V oldValue, Executor executor) throws Exception { requireNonNull(key); requireNonNull(executor); return CompletableFuture.supplyAsync(() -> { diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheWriter.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheWriter.java index 88122a6dab..2a7890bdf3 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheWriter.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CacheWriter.java @@ -15,7 +15,6 @@ */ package com.github.benmanes.caffeine.cache; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -40,7 +39,7 @@ public interface CacheWriter { * @param value the value associated with {@code key} that should be written * @throws RuntimeException or Error, in which case the mapping is unchanged */ - void write(@NonNull K key, @NonNull V value); + void write(K key, V value); /** * Deletes the value corresponding to the {@code key} from the external resource. The cache will @@ -51,7 +50,7 @@ public interface CacheWriter { * @param cause the reason for which the entry was removed * @throws RuntimeException or Error, in which case the mapping is unchanged */ - void delete(@NonNull K key, @Nullable V value, @NonNull RemovalCause cause); + void delete(K key, @Nullable V value, RemovalCause cause); /** * Returns a writer that does nothing. @@ -60,7 +59,7 @@ public interface CacheWriter { * @param the type of values * @return a writer that performs no operations */ - static @NonNull CacheWriter disabledWriter() { + static CacheWriter disabledWriter() { @SuppressWarnings("unchecked") CacheWriter writer = (CacheWriter) DisabledWriter.INSTANCE; return writer; diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java index b480aa898d..d9a5070fe9 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Caffeine.java @@ -36,7 +36,6 @@ import java.util.function.Supplier; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.Async.AsyncExpiry; @@ -221,7 +220,6 @@ static long ceilingPowerOfTwo(long x) { * * @return a new instance with default settings */ - @NonNull public static Caffeine newBuilder() { return new Caffeine<>(); } @@ -232,7 +230,6 @@ public static Caffeine newBuilder() { * @param spec the specification to build from * @return a new instance with the specification's settings */ - @NonNull public static Caffeine from(CaffeineSpec spec) { Caffeine builder = spec.toBuilder(); builder.strictParsing = false; @@ -245,7 +242,6 @@ public static Caffeine from(CaffeineSpec spec) { * @param spec a String in the format specified by {@link CaffeineSpec} * @return a new instance with the specification's settings */ - @NonNull public static Caffeine from(String spec) { return from(CaffeineSpec.parse(spec)); } @@ -260,7 +256,6 @@ public static Caffeine from(String spec) { * @throws IllegalArgumentException if {@code initialCapacity} is negative * @throws IllegalStateException if an initial capacity was already set */ - @NonNull public Caffeine initialCapacity(@NonNegative int initialCapacity) { requireState(this.initialCapacity == UNSET_INT, "initial capacity was already set to %s", this.initialCapacity); @@ -294,14 +289,12 @@ int getInitialCapacity() { * @return this {@code Caffeine} instance (for chaining) * @throws NullPointerException if the specified executor is null */ - @NonNull - public Caffeine executor(@NonNull Executor executor) { + public Caffeine executor(Executor executor) { requireState(this.executor == null, "executor was already set to %s", this.executor); this.executor = requireNonNull(executor); return this; } - @NonNull Executor getExecutor() { return (executor == null) ? ForkJoinPool.commonPool() : executor; } @@ -327,14 +320,12 @@ Executor getExecutor() { * @return this {@code Caffeine} instance (for chaining) * @throws NullPointerException if the specified scheduler is null */ - @NonNull - public Caffeine scheduler(@NonNull Scheduler scheduler) { + public Caffeine scheduler(Scheduler scheduler) { requireState(this.scheduler == null, "scheduler was already set to %s", this.scheduler); this.scheduler = requireNonNull(scheduler); return this; } - @NonNull Scheduler getScheduler() { if ((scheduler == null) || (scheduler == Scheduler.disabledScheduler())) { return Scheduler.disabledScheduler(); @@ -363,7 +354,6 @@ Scheduler getScheduler() { * @throws IllegalArgumentException if {@code size} is negative * @throws IllegalStateException if a maximum size or weight was already set */ - @NonNull public Caffeine maximumSize(@NonNegative long maximumSize) { requireState(this.maximumSize == UNSET_INT, "maximum size was already set to %s", this.maximumSize); @@ -400,7 +390,6 @@ public Caffeine maximumSize(@NonNegative long maximumSize) { * @throws IllegalArgumentException if {@code maximumWeight} is negative * @throws IllegalStateException if a maximum weight or size was already set */ - @NonNull public Caffeine maximumWeight(@NonNegative long maximumWeight) { requireState(this.maximumWeight == UNSET_INT, "maximum weight was already set to %s", this.maximumWeight); @@ -441,9 +430,8 @@ public Caffeine maximumWeight(@NonNegative long maximumWeight) { * remaining configuration and cache building * @throws IllegalStateException if a weigher was already set */ - @NonNull public Caffeine weigher( - @NonNull Weigher weigher) { + Weigher weigher) { requireNonNull(weigher); requireState(this.weigher == null, "weigher was already set to %s", this.weigher); requireState(!strictParsing || this.maximumSize == UNSET_INT, @@ -467,7 +455,7 @@ long getMaximum() { return isWeighted() ? maximumWeight : maximumSize; } - @NonNull @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked", "rawtypes"}) Weigher getWeigher(boolean isAsync) { Weigher delegate = (weigher == null) || (weigher == Weigher.singletonWeigher()) ? Weigher.singletonWeigher() @@ -493,7 +481,6 @@ Weigher getWeigher(boolean isAsync) { * @return this {@code Caffeine} instance (for chaining) * @throws IllegalStateException if the key strength was already set or the writer was set */ - @NonNull public Caffeine weakKeys() { requireState(keyStrength == null, "Key strength was already set to %s", keyStrength); requireState(writer == null, "Weak keys may not be used with CacheWriter"); @@ -525,7 +512,6 @@ boolean isStrongKeys() { * @return this {@code Caffeine} instance (for chaining) * @throws IllegalStateException if the value strength was already set */ - @NonNull public Caffeine weakValues() { requireState(valueStrength == null, "Value strength was already set to %s", valueStrength); valueStrength = Strength.WEAK; @@ -562,7 +548,6 @@ boolean isWeakValues() { * @return this {@code Caffeine} instance (for chaining) * @throws IllegalStateException if the value strength was already set */ - @NonNull public Caffeine softValues() { requireState(valueStrength == null, "Value strength was already set to %s", valueStrength); valueStrength = Strength.SOFT; @@ -584,8 +569,7 @@ public Caffeine softValues() { * @throws IllegalStateException if the time to live or time to idle was already set * @throws ArithmeticException for durations greater than +/- approximately 292 years */ - @NonNull - public Caffeine expireAfterWrite(@NonNull Duration duration) { + public Caffeine expireAfterWrite(Duration duration) { return expireAfterWrite(saturatedToNanos(duration), TimeUnit.NANOSECONDS); } @@ -607,8 +591,7 @@ public Caffeine expireAfterWrite(@NonNull Duration duration) { * @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalStateException if the time to live or variable expiration was already set */ - @NonNull - public Caffeine expireAfterWrite(@NonNegative long duration, @NonNull TimeUnit unit) { + public Caffeine expireAfterWrite(@NonNegative long duration, TimeUnit unit) { requireState(expireAfterWriteNanos == UNSET_INT, "expireAfterWrite was already set to %s ns", expireAfterWriteNanos); requireState(expiry == null, "expireAfterWrite may not be used with variable expiration"); @@ -643,8 +626,7 @@ boolean expiresAfterWrite() { * @throws IllegalStateException if the time to idle or time to live was already set * @throws ArithmeticException for durations greater than +/- approximately 292 years */ - @NonNull - public Caffeine expireAfterAccess(@NonNull Duration duration) { + public Caffeine expireAfterAccess(Duration duration) { return expireAfterAccess(saturatedToNanos(duration), TimeUnit.NANOSECONDS); } @@ -669,8 +651,7 @@ public Caffeine expireAfterAccess(@NonNull Duration duration) { * @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalStateException if the time to idle or variable expiration was already set */ - @NonNull - public Caffeine expireAfterAccess(@NonNegative long duration, @NonNull TimeUnit unit) { + public Caffeine expireAfterAccess(@NonNegative long duration, TimeUnit unit) { requireState(expireAfterAccessNanos == UNSET_INT, "expireAfterAccess was already set to %s ns", expireAfterAccessNanos); requireState(expiry == null, "expireAfterAccess may not be used with variable expiration"); @@ -704,9 +685,8 @@ boolean expiresAfterAccess() { * @return this {@code Caffeine} instance (for chaining) * @throws IllegalStateException if expiration was already set */ - @NonNull public Caffeine expireAfter( - @NonNull Expiry expiry) { + Expiry expiry) { requireNonNull(expiry); requireState(this.expiry == null, "Expiry was already set to %s", this.expiry); requireState(this.expireAfterAccessNanos == UNSET_INT, @@ -750,8 +730,7 @@ boolean expiresVariable() { * @throws IllegalStateException if the refresh interval was already set * @throws ArithmeticException for durations greater than +/- approximately 292 years */ - @NonNull - public Caffeine refreshAfterWrite(@NonNull Duration duration) { + public Caffeine refreshAfterWrite(Duration duration) { return refreshAfterWrite(saturatedToNanos(duration), TimeUnit.NANOSECONDS); } @@ -777,8 +756,7 @@ public Caffeine refreshAfterWrite(@NonNull Duration duration) { * @throws IllegalArgumentException if {@code duration} is zero or negative * @throws IllegalStateException if the refresh interval was already set */ - @NonNull - public Caffeine refreshAfterWrite(@NonNegative long duration, @NonNull TimeUnit unit) { + public Caffeine refreshAfterWrite(@NonNegative long duration, TimeUnit unit) { requireNonNull(unit); requireState(refreshAfterWriteNanos == UNSET_INT, "refreshAfterWriteNanos was already set to %s ns", refreshAfterWriteNanos); @@ -807,14 +785,12 @@ boolean refreshAfterWrite() { * @throws IllegalStateException if a ticker was already set * @throws NullPointerException if the specified ticker is null */ - @NonNull - public Caffeine ticker(@NonNull Ticker ticker) { + public Caffeine ticker(Ticker ticker) { requireState(this.ticker == null, "Ticker was already set to %s", this.ticker); this.ticker = requireNonNull(ticker); return this; } - @NonNull Ticker getTicker() { boolean useTicker = expiresVariable() || expiresAfterAccess() || expiresAfterWrite() || refreshAfterWrite() || isRecordingStats(); @@ -848,9 +824,8 @@ Ticker getTicker() { * @throws IllegalStateException if a removal listener was already set * @throws NullPointerException if the specified removal listener is null */ - @NonNull public Caffeine removalListener( - @NonNull RemovalListener removalListener) { + RemovalListener removalListener) { requireState(this.removalListener == null, "removal listener was already set to %s", this.removalListener); @@ -896,9 +871,8 @@ public Caffeine removalListener( * @throws IllegalStateException if a writer was already set or if the key strength is weak * @throws NullPointerException if the specified writer is null */ - @NonNull public Caffeine writer( - @NonNull CacheWriter writer) { + CacheWriter writer) { requireState(this.writer == null, "Writer was already set to %s", this.writer); requireState(keyStrength == null, "Weak keys may not be used with CacheWriter"); @@ -922,7 +896,6 @@ CacheWriter getCacheWriter() { * * @return this {@code Caffeine} instance (for chaining) */ - @NonNull public Caffeine recordStats() { requireState(this.statsCounterSupplier == null, "Statistics recording was already set"); statsCounterSupplier = ENABLED_STATS_COUNTER_SUPPLIER; @@ -939,9 +912,7 @@ public Caffeine recordStats() { * @param statsCounterSupplier a supplier instance that returns a new {@link StatsCounter} * @return this {@code Caffeine} instance (for chaining) */ - @NonNull - public Caffeine recordStats( - @NonNull Supplier statsCounterSupplier) { + public Caffeine recordStats(Supplier statsCounterSupplier) { requireState(this.statsCounterSupplier == null, "Statistics recording was already set"); requireNonNull(statsCounterSupplier); this.statsCounterSupplier = () -> StatsCounter.guardedStatsCounter(statsCounterSupplier.get()); @@ -952,7 +923,6 @@ boolean isRecordingStats() { return (statsCounterSupplier != null); } - @NonNull Supplier getStatsCounterSupplier() { return (statsCounterSupplier == null) ? StatsCounter::disabledStatsCounter @@ -984,7 +954,6 @@ boolean isBounded() { * @param the value type of the cache * @return a cache having the requested features */ - @NonNull public Cache build() { requireWeightWithWeigher(); requireNonLoadingCache(); @@ -1010,9 +979,8 @@ public Cache build() { * @param the value type of the loader * @return a cache having the requested features */ - @NonNull public LoadingCache build( - @NonNull CacheLoader loader) { + CacheLoader loader) { requireWeightWithWeigher(); @SuppressWarnings("unchecked") @@ -1042,7 +1010,6 @@ public LoadingCache build( * @param the value type of the cache * @return a cache having the requested features */ - @NonNull public AsyncCache buildAsync() { requireState(valueStrength == null, "Weak or soft values can not be combined with AsyncCache"); requireState(writer == null, "CacheWriter can not be combined with AsyncCache"); @@ -1074,9 +1041,8 @@ public AsyncCache buildAsync() { * @param the value type of the loader * @return a cache having the requested features */ - @NonNull public AsyncLoadingCache buildAsync( - @NonNull CacheLoader loader) { + CacheLoader loader) { return buildAsync((AsyncCacheLoader) loader); } @@ -1098,9 +1064,8 @@ public AsyncLoadingCache buildAsync( * @param the value type of the loader * @return a cache having the requested features */ - @NonNull public AsyncLoadingCache buildAsync( - @NonNull AsyncCacheLoader loader) { + AsyncCacheLoader loader) { requireState(valueStrength == null, "Weak or soft values can not be combined with AsyncLoadingCache"); requireState(writer == null, "CacheWriter can not be combined with AsyncLoadingCache"); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CaffeineSpec.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CaffeineSpec.java index 5c6b4c0e50..346624e68a 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CaffeineSpec.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CaffeineSpec.java @@ -24,7 +24,6 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.Caffeine.Strength; @@ -142,7 +141,7 @@ Caffeine toBuilder() { * @return the parsed specification */ @SuppressWarnings("StringSplitter") - public static @NonNull CaffeineSpec parse(@NonNull String specification) { + public static CaffeineSpec parse(String specification) { CaffeineSpec spec = new CaffeineSpec(specification); for (String option : specification.split(SPLIT_OPTIONS)) { spec.parseOption(option.trim()); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Expiry.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Expiry.java index 824dee11f4..9d982de2a9 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Expiry.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Expiry.java @@ -16,7 +16,6 @@ package com.github.benmanes.caffeine.cache; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; /** * Calculates when cache entries expire. A single expiration time is retained so that the lifetime @@ -40,7 +39,7 @@ public interface Expiry { * @param currentTime the current time, in nanoseconds * @return the length of time before the entry expires, in nanoseconds */ - long expireAfterCreate(@NonNull K key, @NonNull V value, long currentTime); + long expireAfterCreate(K key, V value, long currentTime); /** * Specifies that the entry should be automatically removed from the cache once the duration has @@ -58,8 +57,7 @@ public interface Expiry { * @param currentDuration the current duration, in nanoseconds * @return the length of time before the entry expires, in nanoseconds */ - long expireAfterUpdate(@NonNull K key, @NonNull V value, - long currentTime, @NonNegative long currentDuration); + long expireAfterUpdate(K key, V value, long currentTime, @NonNegative long currentDuration); /** * Specifies that the entry should be automatically removed from the cache once the duration has @@ -77,6 +75,5 @@ long expireAfterUpdate(@NonNull K key, @NonNull V value, * @param currentDuration the current duration, in nanoseconds * @return the length of time before the entry expires, in nanoseconds */ - long expireAfterRead(@NonNull K key, @NonNull V value, - long currentTime, @NonNegative long currentDuration); + long expireAfterRead(K key, V value, long currentTime, @NonNegative long currentDuration); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java index fade2fcfbc..fc6d36c113 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java @@ -18,7 +18,6 @@ import static com.github.benmanes.caffeine.cache.Caffeine.requireArgument; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; /** * A probabilistic multiset for estimating the popularity of an element within a time window. The @@ -107,7 +106,7 @@ public boolean isNotInitialized() { * @return the estimated number of occurrences of the element; possibly zero but never negative */ @NonNegative - public int frequency(@NonNull E e) { + public int frequency(E e) { if (isNotInitialized()) { return 0; } @@ -130,7 +129,7 @@ public int frequency(@NonNull E e) { * * @param e the element to add */ - public void increment(@NonNull E e) { + public void increment(E e) { if (isNotInitialized()) { return; } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LoadingCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LoadingCache.java index 06c9e7f25e..6eaace5ca9 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LoadingCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LoadingCache.java @@ -19,7 +19,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -61,7 +60,7 @@ public interface LoadingCache extends Cache { * is left unestablished */ @Nullable - V get(@NonNull K key); + V get(K key); /** * Returns a map of the values associated with the {@code keys}, creating or retrieving those @@ -89,8 +88,7 @@ public interface LoadingCache extends Cache { * values, or fails to return an entry for each requested key. In all cases, the mapping * is left unestablished */ - @NonNull - Map<@NonNull K, @NonNull V> getAll(@NonNull Iterable keys); + Map getAll(Iterable keys); /** * Loads a new value for the {@code key}, asynchronously. While the new value is loading the @@ -110,6 +108,5 @@ public interface LoadingCache extends Cache { * @return the future that is loading the value * @throws NullPointerException if the specified key is null */ - @NonNull - CompletableFuture refresh(@NonNull K key); + CompletableFuture refresh(K key); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java index 1b0adffe8e..0e823c80d8 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java @@ -41,7 +41,6 @@ import java.util.function.BiFunction; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.LocalAsyncCache.AsyncBulkCompleter.NullMapCompletionException; @@ -63,13 +62,12 @@ interface LocalAsyncCache extends AsyncCache { Policy policy(); @Override - default @Nullable CompletableFuture getIfPresent(@NonNull K key) { + default @Nullable CompletableFuture getIfPresent(K key) { return cache().getIfPresent(key, /* recordStats */ true); } @Override - default CompletableFuture get(@NonNull K key, - @NonNull Function mappingFunction) { + default CompletableFuture get(K key, Function mappingFunction) { requireNonNull(mappingFunction); return get(key, (k1, executor) -> CompletableFuture.supplyAsync( () -> mappingFunction.apply(key), executor)); @@ -98,7 +96,7 @@ default CompletableFuture get(K key, } @Override - default CompletableFuture> getAll(Iterable keys, + default CompletableFuture> getAll(Iterable keys, Function, Map> mappingFunction) { requireNonNull(mappingFunction); return getAll(keys, (keysToLoad, executor) -> @@ -107,7 +105,7 @@ default CompletableFuture> getAll(Iterable keys, @Override @SuppressWarnings("FutureReturnValueIgnored") - default CompletableFuture> getAll(Iterable keys, + default CompletableFuture> getAll(Iterable keys, BiFunction, Executor, CompletableFuture>> mappingFunction) { requireNonNull(mappingFunction); requireNonNull(keys); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java index 03e16508d7..7b470c04fb 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalCache.java @@ -22,7 +22,6 @@ import java.util.function.BiFunction; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.stats.StatsCounter; @@ -39,7 +38,7 @@ interface LocalCache extends ConcurrentMap { boolean isRecordingStats(); /** Returns the {@link StatsCounter} used by this cache. */ - @NonNull StatsCounter statsCounter(); + StatsCounter statsCounter(); /** Returns whether this cache notifies when an entry is removed. */ boolean hasRemovalListener(); @@ -51,7 +50,7 @@ interface LocalCache extends ConcurrentMap { void notifyRemoval(@Nullable K key, @Nullable V value, RemovalCause cause); /** Returns the {@link Executor} used by this cache. */ - @NonNull Executor executor(); + Executor executor(); /** Returns the map of in-flight refresh operations. */ ConcurrentMap> refreshes(); @@ -63,10 +62,10 @@ interface LocalCache extends ConcurrentMap { @Nullable Expiry expiry(); /** Returns the {@link Ticker} used by this cache for expiration. */ - @NonNull Ticker expirationTicker(); + Ticker expirationTicker(); /** Returns the {@link Ticker} used by this cache for statistics. */ - @NonNull Ticker statsTicker(); + Ticker statsTicker(); /** See {@link Cache#estimatedSize()}. */ long estimatedSize(); @@ -79,25 +78,24 @@ interface LocalCache extends ConcurrentMap { * to record the hit and miss statistics based on the success of this operation. */ @Nullable - V getIfPresent(@NonNull K key, boolean recordStats); + V getIfPresent(K key, boolean recordStats); /** * See {@link Cache#getIfPresent(K)}. This method differs by not recording the access with * the statistics nor the eviction policy, and populates the write time if known. */ @Nullable - V getIfPresentQuietly(@NonNull K key, @NonNull long[/* 1 */] writeTime); + V getIfPresentQuietly(K key, long[/* 1 */] writeTime); /** See {@link Cache#getAllPresent}. */ - @NonNull - Map getAllPresent(@NonNull Iterable keys); + Map getAllPresent(Iterable keys); /** * See {@link Cache#put(Object, Object)}. This method differs by allowing the operation to not * notify the writer when an entry was inserted or updated. */ @Nullable - V put(@NonNull K key, @NonNull V value, boolean notifyWriter); + V put(K key, V value, boolean notifyWriter); @Override default @Nullable V compute(K key, diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalManualCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalManualCache.java index 3531408a0a..4e81348bc7 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalManualCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalManualCache.java @@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.stats.CacheStats; @@ -58,6 +57,7 @@ default void cleanUp() { } @Override + @SuppressWarnings("NullAway") default @Nullable V get(K key, Function mappingFunction) { return cache().computeIfAbsent(key, mappingFunction); } @@ -95,7 +95,7 @@ default Map getAll(Iterable keys, * during the load are replaced when the loaded entries are inserted into the cache. */ default void bulkLoad(Set keysToLoad, Map result, - Function, @NonNull Map> mappingFunction) { + Function, Map> mappingFunction) { boolean success = false; long startTime = cache().statsTicker().read(); try { diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Node.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Node.java index 9b9058e113..d0ef1759fd 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Node.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Node.java @@ -18,7 +18,6 @@ import java.lang.ref.ReferenceQueue; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.AccessOrderDeque.AccessOrder; @@ -42,7 +41,6 @@ abstract class Node implements AccessOrder>, WriteOrder implements AccessOrder>, WriteOrder implements AccessOrder>, WriteOrder referenceQueue); + public abstract void setValue(V value, @Nullable ReferenceQueue referenceQueue); /** * Returns {@code true} if the given objects are considered equivalent. A strongly held value is * compared by equality and a weakly or softly held value is compared by identity. */ - public abstract boolean containsValue(@NonNull Object value); + public abstract boolean containsValue(Object value); /** Returns the weight of this entry from the entry's perspective. */ @NonNegative diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java index d6e6bd6450..8db305e4a9 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Policy.java @@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -54,7 +53,7 @@ public interface Policy { * @throws NullPointerException if the specified key is null */ @Nullable - V getIfPresentQuietly(@NonNull K key); + V getIfPresentQuietly(K key); /** * Returns access to perform operations based on the maximum size or maximum weight eviction @@ -63,7 +62,6 @@ public interface Policy { * * @return access to low-level operations for this cache if an eviction policy is used */ - @NonNull Optional> eviction(); /** @@ -80,7 +78,6 @@ public interface Policy { * @return access to low-level operations for this cache if a time-to-idle expiration policy is * used */ - @NonNull Optional> expireAfterAccess(); /** @@ -94,7 +91,6 @@ public interface Policy { * @return access to low-level operations for this cache if a time-to-live expiration policy is * used */ - @NonNull Optional> expireAfterWrite(); /** @@ -107,7 +103,6 @@ public interface Policy { * * @return access to low-level operations for this cache if a variable expiration policy is used */ - @NonNull Optional> expireVariably(); /** @@ -120,7 +115,6 @@ public interface Policy { * * @return access to low-level operations for this cache if a time-to-live refresh policy is used */ - @NonNull Optional> refreshAfterWrite(); /** The low-level operations for a cache with a size-based eviction policy. */ @@ -140,8 +134,7 @@ interface Eviction { * @param key the key for the entry being queried * @return the weight if the entry is present in the cache */ - @NonNull - OptionalInt weightOf(@NonNull K key); + OptionalInt weightOf(K key); /** * Returns the approximate accumulated weight of entries in this cache. If this cache does not @@ -149,7 +142,6 @@ interface Eviction { * * @return the combined weight of the values in this cache */ - @NonNull OptionalLong weightedSize(); /** @@ -190,8 +182,7 @@ interface Eviction { * the limit) * @return a snapshot view of the cache from coldest entry to the hottest */ - @NonNull - Map<@NonNull K, @NonNull V> coldest(@NonNegative int limit); + Map coldest(@NonNegative int limit); /** * Returns an unmodifiable snapshot {@link Map} view of the cache with ordered traversal. The @@ -207,8 +198,7 @@ interface Eviction { * the limit) * @return a snapshot view of the cache from hottest entry to the coldest */ - @NonNull - Map<@NonNull K, @NonNull V> hottest(@NonNegative int limit); + Map hottest(@NonNegative int limit); } /** The low-level operations for a cache with a fixed expiration policy. */ @@ -228,8 +218,7 @@ interface FixedExpiration { * @param unit the unit that {@code age} is expressed in * @return the age if the entry is present in the cache */ - @NonNull - OptionalLong ageOf(@NonNull K key, @NonNull TimeUnit unit); + OptionalLong ageOf(K key, TimeUnit unit); /** * Returns the age of the entry based on the expiration policy. The entry's age is the cache's @@ -242,8 +231,7 @@ interface FixedExpiration { * @param key the key for the entry being queried * @return the age if the entry is present in the cache */ - @NonNull - default Optional ageOf(@NonNull K key) { + default Optional ageOf(K key) { OptionalLong duration = ageOf(key, TimeUnit.NANOSECONDS); return duration.isPresent() ? Optional.of(Duration.ofNanos(duration.getAsLong())) @@ -262,7 +250,7 @@ default Optional ageOf(@NonNull K key) { * @return the length of time after which an entry should be automatically removed */ @NonNegative - long getExpiresAfter(@NonNull TimeUnit unit); + long getExpiresAfter(TimeUnit unit); /** * Returns the fixed duration used to determine if an entry should be automatically removed due @@ -272,7 +260,6 @@ default Optional ageOf(@NonNull K key) { * * @return the length of time after which an entry should be automatically removed */ - @NonNull default Duration getExpiresAfter() { return Duration.ofNanos(getExpiresAfter(TimeUnit.NANOSECONDS)); } @@ -287,7 +274,7 @@ default Duration getExpiresAfter() { * @param unit the unit that {@code duration} is expressed in * @throws IllegalArgumentException if {@code duration} is negative */ - void setExpiresAfter(@NonNegative long duration, @NonNull TimeUnit unit); + void setExpiresAfter(@NonNegative long duration, TimeUnit unit); /** * Specifies that each entry should be automatically removed from the cache once a fixed @@ -296,7 +283,7 @@ default Duration getExpiresAfter() { * @param duration the length of time after which an entry should be automatically removed * @throws IllegalArgumentException if {@code duration} is negative */ - default void setExpiresAfter(@NonNull Duration duration) { + default void setExpiresAfter(Duration duration) { setExpiresAfter(duration.toNanos(), TimeUnit.NANOSECONDS); } @@ -314,8 +301,7 @@ default void setExpiresAfter(@NonNull Duration duration) { * the limit) * @return a snapshot view of the cache from oldest entry to the youngest */ - @NonNull - Map<@NonNull K, @NonNull V> oldest(@NonNegative int limit); + Map oldest(@NonNegative int limit); /** * Returns an unmodifiable snapshot {@link Map} view of the cache with ordered traversal. The @@ -331,8 +317,7 @@ default void setExpiresAfter(@NonNull Duration duration) { * the limit) * @return a snapshot view of the cache from youngest entry to the oldest */ - @NonNull - Map<@NonNull K, @NonNull V> youngest(@NonNegative int limit); + Map youngest(@NonNegative int limit); } /** The low-level operations for a cache with a variable expiration policy. */ @@ -348,8 +333,7 @@ interface VarExpiration { * @param unit the unit that {@code age} is expressed in * @return the duration if the entry is present in the cache */ - @NonNull - OptionalLong getExpiresAfter(@NonNull K key, @NonNull TimeUnit unit); + OptionalLong getExpiresAfter(K key, TimeUnit unit); /** * Returns the duration until the entry should be automatically removed. The expiration policy @@ -358,8 +342,7 @@ interface VarExpiration { * @param key the key for the entry being queried * @return the duration if the entry is present in the cache */ - @NonNull - default Optional getExpiresAfter(@NonNull K key) { + default Optional getExpiresAfter(K key) { OptionalLong duration = getExpiresAfter(key, TimeUnit.NANOSECONDS); return duration.isPresent() ? Optional.of(Duration.ofNanos(duration.getAsLong())) @@ -376,7 +359,7 @@ default Optional getExpiresAfter(@NonNull K key) { * @throws IllegalArgumentException if {@code duration} is negative * @throws NullPointerException if the unit is null */ - void setExpiresAfter(@NonNull K key, @NonNegative long duration, @NonNull TimeUnit unit); + void setExpiresAfter(K key, @NonNegative long duration, TimeUnit unit); /** * Specifies that the entry should be automatically removed from the cache once the duration has @@ -386,7 +369,7 @@ default Optional getExpiresAfter(@NonNull K key) { * @param duration the length of time from now when the entry should be automatically removed * @throws IllegalArgumentException if {@code duration} is negative */ - default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { + default void setExpiresAfter(K key, Duration duration) { setExpiresAfter(key, duration.toNanos(), TimeUnit.NANOSECONDS); } @@ -406,8 +389,7 @@ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { * mapping for the key. * @throws IllegalArgumentException if {@code duration} is negative */ - @Nullable V putIfAbsent(@NonNull K key, @NonNull V value, - @NonNegative long duration, @NonNull TimeUnit unit); + @Nullable V putIfAbsent(K key, V value, @NonNegative long duration, TimeUnit unit); /** * Associates the {@code value} with the {@code key} in this cache if the specified key is not @@ -422,7 +404,7 @@ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { * mapping for the key. * @throws IllegalArgumentException if {@code duration} is negative */ - default @Nullable V putIfAbsent(@NonNull K key, @NonNull V value, @NonNull Duration duration) { + default @Nullable V putIfAbsent(K key, V value, Duration duration) { return putIfAbsent(key, value, duration.toNanos(), TimeUnit.NANOSECONDS); } @@ -443,8 +425,7 @@ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { * @throws IllegalArgumentException if {@code duration} is negative * @throws NullPointerException if the specified key or value is null */ - @Nullable V put(@NonNull K key, @NonNull V value, - @NonNegative long duration, @NonNull TimeUnit unit); + @Nullable V put(K key, V value, @NonNegative long duration, TimeUnit unit); /** * Associates the {@code value} with the {@code key} in this cache. If the cache previously @@ -460,7 +441,7 @@ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { * @throws IllegalArgumentException if {@code duration} is negative * @throws NullPointerException if the specified key or value is null */ - default @Nullable V put(@NonNull K key, @NonNull V value, @NonNull Duration duration) { + default @Nullable V put(K key, V value, Duration duration) { return put(key, value, duration.toNanos(), TimeUnit.NANOSECONDS); } @@ -478,8 +459,7 @@ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { * the limit) * @return a snapshot view of the cache from oldest entry to the youngest */ - @NonNull - Map<@NonNull K, @NonNull V> oldest(@NonNegative int limit); + Map oldest(@NonNegative int limit); /** * Returns an unmodifiable snapshot {@link Map} view of the cache with ordered traversal. The @@ -495,8 +475,7 @@ default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) { * the limit) * @return a snapshot view of the cache from youngest entry to the oldest */ - @NonNull - Map<@NonNull K, @NonNull V> youngest(@NonNegative int limit); + Map youngest(@NonNegative int limit); } /** The low-level operations for a cache with a fixed refresh policy. */ @@ -516,8 +495,7 @@ interface FixedRefresh { * @param unit the unit that {@code age} is expressed in * @return the age if the entry is present in the cache */ - @NonNull - OptionalLong ageOf(@NonNull K key, @NonNull TimeUnit unit); + OptionalLong ageOf(K key, TimeUnit unit); /** * Returns the age of the entry based on the expiration policy. The entry's age is the cache's @@ -530,8 +508,7 @@ interface FixedRefresh { * @param key the key for the entry being queried * @return the age if the entry is present in the cache */ - @NonNull - default Optional ageOf(@NonNull K key) { + default Optional ageOf(K key) { OptionalLong duration = ageOf(key, TimeUnit.NANOSECONDS); return duration.isPresent() ? Optional.of(Duration.ofNanos(duration.getAsLong())) @@ -550,7 +527,7 @@ default Optional ageOf(@NonNull K key) { * @return the length of time after which an entry is eligible to be reloaded */ @NonNegative - long getRefreshesAfter(@NonNull TimeUnit unit); + long getRefreshesAfter(TimeUnit unit); /** * Returns the fixed duration used to determine if an entry should be eligible for reloading due @@ -560,7 +537,6 @@ default Optional ageOf(@NonNull K key) { * * @return the length of time after which an entry is eligible to be reloaded */ - @NonNull default Duration getRefreshesAfter() { return Duration.ofNanos(getRefreshesAfter(TimeUnit.NANOSECONDS)); } @@ -575,7 +551,7 @@ default Duration getRefreshesAfter() { * @param unit the unit that {@code duration} is expressed in * @throws IllegalArgumentException if {@code duration} is negative */ - void setRefreshesAfter(@NonNegative long duration, @NonNull TimeUnit unit); + void setRefreshesAfter(@NonNegative long duration, TimeUnit unit); /** * Specifies that each entry should be eligible for reloading once a fixed duration has elapsed. @@ -584,7 +560,7 @@ default Duration getRefreshesAfter() { * @param duration the length of time after which an entry is eligible to be reloaded * @throws IllegalArgumentException if {@code duration} is negative */ - default void setRefreshesAfter(@NonNull Duration duration) { + default void setRefreshesAfter(Duration duration) { setRefreshesAfter(duration.toNanos(), TimeUnit.NANOSECONDS); } } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/References.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/References.java index 95f568a189..717101e48d 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/References.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/References.java @@ -21,7 +21,6 @@ import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -54,7 +53,6 @@ interface InternalReference { * * @return the key that is associated to the cached entry */ - @NonNull Object getKeyReference(); /** @@ -84,7 +82,7 @@ static final class LookupKeyReference implements InternalReference { private final int hashCode; private final E e; - public LookupKeyReference(@NonNull E e) { + public LookupKeyReference(E e) { this.hashCode = System.identityHashCode(e); this.e = requireNonNull(e); } @@ -148,7 +146,7 @@ static final class WeakValueReference extends WeakReference implements InternalReference { private final Object keyReference; - public WeakValueReference(@NonNull Object keyReference, + public WeakValueReference(Object keyReference, @Nullable V value, @Nullable ReferenceQueue queue) { super(value, queue); this.keyReference = keyReference; @@ -180,7 +178,7 @@ static final class SoftValueReference extends SoftReference implements InternalReference { private final Object keyReference; - public SoftValueReference(@NonNull Object keyReference, + public SoftValueReference(Object keyReference, @Nullable V value, @Nullable ReferenceQueue queue) { super(value, queue); this.keyReference = keyReference; diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/RemovalListener.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/RemovalListener.java index fd84bbd50c..963e6b2a5e 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/RemovalListener.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/RemovalListener.java @@ -15,7 +15,6 @@ */ package com.github.benmanes.caffeine.cache; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -46,5 +45,5 @@ public interface RemovalListener { * @param value the value represented by this entry, or {@code null} if collected * @param cause the reason for which the entry was removed */ - void onRemoval(@Nullable K key, @Nullable V value, @NonNull RemovalCause cause); + void onRemoval(@Nullable K key, @Nullable V value, RemovalCause cause); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Scheduler.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Scheduler.java index 091ad0e804..a3454c1679 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Scheduler.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Scheduler.java @@ -28,9 +28,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.checkerframework.checker.index.qual.Positive; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * A scheduler that submits a task to an executor after a given delay. * @@ -48,15 +45,14 @@ public interface Scheduler { * @param unit a {@code TimeUnit} determining how to interpret the {@code delay} parameter * @return a scheduled future representing pending submission of the task */ - @NonNull Future schedule(@NonNull Executor executor, - @NonNull Runnable command, @Positive long delay, @NonNull TimeUnit unit); + Future schedule(Executor executor, Runnable command, long delay, TimeUnit unit); /** * Returns a scheduler that always returns a successfully completed future. * * @return a scheduler that always returns a successfully completed future */ - static @NonNull Scheduler disabledScheduler() { + static Scheduler disabledScheduler() { return DisabledScheduler.INSTANCE; } @@ -66,7 +62,7 @@ public interface Scheduler { * * @return a scheduler that uses the system-wide scheduling thread */ - static @NonNull Scheduler systemScheduler() { + static Scheduler systemScheduler() { return SystemScheduler.INSTANCE; } @@ -76,8 +72,7 @@ public interface Scheduler { * @param scheduledExecutorService the executor to schedule on * @return a scheduler that delegates to the a {@link ScheduledExecutorService} */ - static @NonNull Scheduler forScheduledExecutorService( - @NonNull ScheduledExecutorService scheduledExecutorService) { + static Scheduler forScheduledExecutorService(ScheduledExecutorService scheduledExecutorService) { return new ExecutorServiceScheduler(scheduledExecutorService); } @@ -88,7 +83,7 @@ public interface Scheduler { * @param scheduler the scheduler to delegate to * @return an scheduler that suppresses and logs any exception thrown by the delegate */ - static @NonNull Scheduler guardedScheduler(@NonNull Scheduler scheduler) { + static Scheduler guardedScheduler(Scheduler scheduler) { return (scheduler instanceof GuardedScheduler) ? scheduler : new GuardedScheduler(scheduler); } } @@ -144,8 +139,7 @@ final class GuardedScheduler implements Scheduler, Serializable { } @Override - public @NonNull Future schedule(@NonNull Executor executor, - @NonNull Runnable command, long delay, @NonNull TimeUnit unit) { + public Future schedule(Executor executor, Runnable command, long delay, TimeUnit unit) { try { Future future = delegate.schedule(executor, command, delay, unit); return (future == null) ? DisabledFuture.INSTANCE : future; diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Ticker.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Ticker.java index 8df2bcedd9..3ec78cdc8d 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Ticker.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Ticker.java @@ -15,8 +15,6 @@ */ package com.github.benmanes.caffeine.cache; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * A time source that returns a time value representing the number of nanoseconds elapsed since some * fixed but arbitrary point in time. @@ -37,7 +35,7 @@ public interface Ticker { * * @return a ticker that reads the current time using {@link System#nanoTime} */ - static @NonNull Ticker systemTicker() { + static Ticker systemTicker() { return SystemTicker.INSTANCE; } @@ -46,7 +44,7 @@ public interface Ticker { * * @return a ticker that always returns {@code 0} */ - static @NonNull Ticker disabledTicker() { + static Ticker disabledTicker() { return DisabledTicker.INSTANCE; } } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java index 105826b596..884e261a34 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java @@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -167,7 +166,7 @@ void expire(int index, long previousTicks, long currentTicks) { * * @param node the entry in the cache */ - public void schedule(@NonNull Node node) { + public void schedule(Node node) { Node sentinel = findBucket(node.getVariableTime()); link(sentinel, node); } @@ -177,7 +176,7 @@ public void schedule(@NonNull Node node) { * * @param node the entry in the cache */ - public void reschedule(@NonNull Node node) { + public void reschedule(Node node) { if (node.getNextInVariableOrder() != null) { unlink(node); schedule(node); @@ -189,7 +188,7 @@ public void reschedule(@NonNull Node node) { * * @param node the entry in the cache */ - public void deschedule(@NonNull Node node) { + public void deschedule(Node node) { unlink(node); node.setNextInVariableOrder(null); node.setPreviousInVariableOrder(null); @@ -290,7 +289,7 @@ long peekAhead(int i) { * @param transformer a function that unwraps the value * @return an unmodifiable snapshot in the desired order */ - public Map snapshot(boolean ascending, int limit, @NonNull Function transformer) { + public Map snapshot(boolean ascending, int limit, Function transformer) { requireArgument(limit >= 0); Map map = new LinkedHashMap<>(Math.min(limit, cache.size())); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Weigher.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Weigher.java index 030ed96982..3901e92622 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Weigher.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Weigher.java @@ -20,7 +20,6 @@ import java.io.Serializable; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; /** * Calculates the weights of cache entries. The total weight threshold is used to determine when an @@ -42,7 +41,7 @@ public interface Weigher { * @return the weight of the entry; must be non-negative */ @NonNegative - int weigh(@NonNull K key, @NonNull V value); + int weigh(K key, V value); /** * Returns a weigher where an entry has a weight of {@code 1}. @@ -51,7 +50,6 @@ public interface Weigher { * @param the type of values * @return a weigher where an entry has a weight of {@code 1} */ - @NonNull static Weigher singletonWeigher() { @SuppressWarnings("unchecked") Weigher self = (Weigher) SingletonWeigher.INSTANCE; @@ -66,8 +64,7 @@ static Weigher singletonWeigher() { * @param the type of values * @return a weigher that enforces that the weight is non-negative */ - @NonNull - static Weigher boundedWeigher(@NonNull Weigher delegate) { + static Weigher boundedWeigher(Weigher delegate) { return new BoundedWeigher<>(delegate); } } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/package-info.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/package-info.java index ff5166bb15..5ffa24718b 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/package-info.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/package-info.java @@ -30,4 +30,11 @@ * * @author ben.manes@gmail.com (Ben Manes) */ +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.FIELD) +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.PARAMETER) +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.RETURN) package com.github.benmanes.caffeine.cache; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.checkerframework.framework.qual.TypeUseLocation; diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/CacheStats.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/CacheStats.java index 11a3d20c3c..a0a5d937f4 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/CacheStats.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/CacheStats.java @@ -18,7 +18,6 @@ import java.util.Objects; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.LoadingCache; @@ -115,7 +114,6 @@ public static CacheStats of(@NonNegative long hitCount, @NonNegative long missCo * * @return an empty statistics instance */ - @NonNull public static CacheStats empty() { return EMPTY_STATS; } @@ -308,8 +306,7 @@ public long evictionWeight() { * @param other the statistics to subtract with * @return the difference between this instance and {@code other} */ - @NonNull - public CacheStats minus(@NonNull CacheStats other) { + public CacheStats minus(CacheStats other) { return CacheStats.of( Math.max(0L, saturatedSubtract(hitCount, other.hitCount)), Math.max(0L, saturatedSubtract(missCount, other.missCount)), @@ -331,8 +328,7 @@ public CacheStats minus(@NonNull CacheStats other) { * @param other the statistics to add with * @return the sum of the statistics */ - @NonNull - public CacheStats plus(@NonNull CacheStats other) { + public CacheStats plus(CacheStats other) { return CacheStats.of( saturatedAdd(hitCount, other.hitCount), saturatedAdd(missCount, other.missCount), diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/ConcurrentStatsCounter.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/ConcurrentStatsCounter.java index 9b2633d42d..1428ac62aa 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/ConcurrentStatsCounter.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/ConcurrentStatsCounter.java @@ -17,8 +17,6 @@ import java.util.concurrent.atomic.LongAdder; -import org.checkerframework.checker.nullness.qual.NonNull; - import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.RemovalCause; @@ -99,7 +97,7 @@ private static long negativeToMaxValue(long value) { * * @param other the counter to increment from */ - public void incrementBy(@NonNull StatsCounter other) { + public void incrementBy(StatsCounter other) { CacheStats otherStats = other.snapshot(); hitCount.add(otherStats.hitCount()); missCount.add(otherStats.missCount()); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/StatsCounter.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/StatsCounter.java index 108bbc2dd1..6b234d903d 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/StatsCounter.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/StatsCounter.java @@ -18,7 +18,6 @@ import java.util.Map; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.RemovalCause; @@ -91,7 +90,6 @@ public interface StatsCounter { * * @return a snapshot of this counter's values */ - @NonNull CacheStats snapshot(); /** @@ -99,7 +97,7 @@ public interface StatsCounter { * * @return an accumulator that does not record metrics */ - static @NonNull StatsCounter disabledStatsCounter() { + static StatsCounter disabledStatsCounter() { return DisabledStatsCounter.INSTANCE; } @@ -110,7 +108,7 @@ public interface StatsCounter { * @param statsCounter the accumulator to delegate to * @return an accumulator that suppresses and logs any exception thrown by the delegate */ - static @NonNull StatsCounter guardedStatsCounter(@NonNull StatsCounter statsCounter) { + static StatsCounter guardedStatsCounter(StatsCounter statsCounter) { return (statsCounter instanceof GuardedStatsCounter) ? statsCounter : new GuardedStatsCounter(statsCounter); diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/package-info.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/package-info.java index 03acbe016c..49c6a4bf59 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/package-info.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/package-info.java @@ -19,4 +19,11 @@ * * @author ben.manes@gmail.com (Ben Manes) */ +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.FIELD) +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.PARAMETER) +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.RETURN) package com.github.benmanes.caffeine.cache.stats; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.checkerframework.framework.qual.TypeUseLocation; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java index b774f262d9..951d1cf0d3 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java @@ -35,8 +35,6 @@ import java.util.function.BiFunction; import java.util.function.Function; -import org.checkerframework.checker.nullness.qual.NonNull; - import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.benmanes.caffeine.cache.Policy; @@ -435,7 +433,7 @@ public Policy policy() { @Override public boolean isRecordingStats() { return isRecordingStats; } - @Override public V getIfPresentQuietly(@NonNull Object key) { + @Override public V getIfPresentQuietly(K key) { return cache.asMap().get(key); } @Override public Optional> eviction() { diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/RemovalNotification.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/RemovalNotification.java index f4c05838fc..c93aee09d6 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/RemovalNotification.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/RemovalNotification.java @@ -19,7 +19,6 @@ import java.util.AbstractMap.SimpleImmutableEntry; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.RemovalCause; @@ -45,7 +44,7 @@ public final class RemovalNotification extends SimpleImmutableEntry * @param value the value represented by this entry * @param cause the reason for which the entry was removed */ - public RemovalNotification(@Nullable K key, @Nullable V value, @NonNull RemovalCause cause) { + public RemovalNotification(@Nullable K key, @Nullable V value, RemovalCause cause) { super(key, value); this.cause = requireNonNull(cause); } @@ -53,7 +52,6 @@ public RemovalNotification(@Nullable K key, @Nullable V value, @NonNull RemovalC /** * @return the cause for which the entry was removed */ - @NonNull public RemovalCause getCause() { return cause; } diff --git a/examples/coalescing-bulkloader/src/main/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloader.java b/examples/coalescing-bulkloader/src/main/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloader.java index 5c2087e89b..5c3b1a8dbd 100644 --- a/examples/coalescing-bulkloader/src/main/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloader.java +++ b/examples/coalescing-bulkloader/src/main/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloader.java @@ -36,7 +36,6 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Stream; -import org.checkerframework.checker.nullness.qual.NonNull; /** * An implementation of {@link AsyncCacheLoader} that delays fetching a bit until "enough" keys are collected @@ -141,7 +140,7 @@ private CoalescingBulkloader(int maxLoadSize, long maxDelay, Consumer asyncLoad(@NonNull Key key, @NonNull Executor executor) { + @Override public CompletableFuture asyncLoad(Key key, Executor executor) { final WaitingKey waitingKey = new WaitingKey(); waitingKey.key = key; waitingKey.future = new CompletableFuture<>(); diff --git a/examples/coalescing-bulkloader/src/test/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloaderTest.java b/examples/coalescing-bulkloader/src/test/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloaderTest.java index 8d00f5de81..9653c30023 100644 --- a/examples/coalescing-bulkloader/src/test/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloaderTest.java +++ b/examples/coalescing-bulkloader/src/test/java/com/github/benmanes/caffeine/examples/coalescing/bulkloader/CoalescingBulkloaderTest.java @@ -35,7 +35,6 @@ import java.util.function.Function; import java.util.stream.Stream; import org.awaitility.Awaitility; -import org.checkerframework.checker.nullness.qual.NonNull; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; @@ -71,7 +70,7 @@ public static List, Stream>, Coalesci ); } - @NonNull private AsyncLoadingCache createCache(AtomicInteger loaderCalled) { + private AsyncLoadingCache createCache(AtomicInteger loaderCalled) { return Caffeine.newBuilder().buildAsync(cbl.apply(ints -> { loaderCalled.incrementAndGet(); try { diff --git a/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuava.java b/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuava.java index 4a23fc2904..83bbd579b9 100644 --- a/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuava.java +++ b/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuava.java @@ -17,8 +17,6 @@ import java.lang.reflect.Method; -import org.checkerframework.checker.nullness.qual.NonNull; - import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.BulkLoader; import com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.SingleLoader; @@ -41,9 +39,7 @@ private CaffeinatedGuava() {} * @param builder the configured cache builder * @return a cache exposed under the Guava APIs */ - @NonNull - public static Cache build( - @NonNull Caffeine builder) { + public static Cache build(Caffeine builder) { return new CaffeinatedGuavaCache<>(builder.build()); } @@ -54,9 +50,8 @@ public static Cache build( * @param loader the cache loader used to obtain new values * @return a cache exposed under the Guava APIs */ - @NonNull public static LoadingCache build( - @NonNull Caffeine builder, @NonNull CacheLoader loader) { + Caffeine builder, CacheLoader loader) { @SuppressWarnings("unchecked") CacheLoader castedLoader = (CacheLoader) loader; return build(builder, hasLoadAll(castedLoader) @@ -71,10 +66,9 @@ public static LoadingCache build( * @param loader the cache loader used to obtain new values * @return a cache exposed under the Guava APIs */ - @NonNull public static LoadingCache build( - @NonNull Caffeine builder, - com.github.benmanes.caffeine.cache.@NonNull CacheLoader loader) { + Caffeine builder, + com.github.benmanes.caffeine.cache.CacheLoader loader) { return new CaffeinatedGuavaLoadingCache<>(builder.build(loader)); } diff --git a/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaLoadingCache.java b/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaLoadingCache.java index 927ef40d02..43f0ab8300 100644 --- a/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaLoadingCache.java +++ b/guava/src/main/java/com/github/benmanes/caffeine/guava/CaffeinatedGuavaLoadingCache.java @@ -23,8 +23,6 @@ import java.util.Set; import java.util.concurrent.ExecutionException; -import org.checkerframework.checker.nullness.qual.NonNull; - import com.github.benmanes.caffeine.cache.CacheLoader; import com.google.common.base.Throwables; import com.google.common.cache.CacheLoader.InvalidCacheLoadException; @@ -113,7 +111,7 @@ public ImmutableMap getAll(Iterable keys) throws ExecutionExc @Override @SuppressWarnings("NullAway") - public V apply(@NonNull K key) { + public V apply(K key) { return cache.get(key); } diff --git a/guava/src/main/java/com/github/benmanes/caffeine/guava/package-info.java b/guava/src/main/java/com/github/benmanes/caffeine/guava/package-info.java new file mode 100644 index 0000000000..cac388c5aa --- /dev/null +++ b/guava/src/main/java/com/github/benmanes/caffeine/guava/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright 2021 Ben Manes. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This package contains an adapter to the Guava cache interfaces. + * + * @author ben.manes@gmail.com (Ben Manes) + */ +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.FIELD) +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.PARAMETER) +@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.RETURN) +package com.github.benmanes.caffeine.guava; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.checkerframework.framework.qual.TypeUseLocation; diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheProxy.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheProxy.java index 27de5ca04e..ceebcca7ae 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheProxy.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/CacheProxy.java @@ -53,7 +53,6 @@ import javax.cache.processor.EntryProcessorException; import javax.cache.processor.EntryProcessorResult; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import com.github.benmanes.caffeine.cache.Ticker; @@ -1064,7 +1063,7 @@ protected final void requireNotClosed() { * @return a copy of the object if storing by value or the same instance if by reference */ @SuppressWarnings("NullAway") - protected final @NonNull T copyOf(@Nullable T object) { + protected final T copyOf(@Nullable T object) { if (object == null) { return null; } diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/FactoryCreator.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/FactoryCreator.java index fae6789732..bab337d86c 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/FactoryCreator.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/configuration/FactoryCreator.java @@ -15,7 +15,6 @@ */ package com.github.benmanes.caffeine.jcache.configuration; -import org.checkerframework.checker.nullness.qual.NonNull; import javax.cache.configuration.Factory; /** @@ -33,6 +32,5 @@ public interface FactoryCreator { * @param the type of the instances being produced * @return a {@link Factory} for the specified class */ - @NonNull Factory factoryOf(String className); } diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/copy/Copier.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/copy/Copier.java index 0f81ea4c14..658f14e726 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/copy/Copier.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/copy/Copier.java @@ -15,8 +15,6 @@ */ package com.github.benmanes.caffeine.jcache.copy; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * An object is copied when the cache is configured with storeByValue to guard against * mutations of the key or value. @@ -34,8 +32,7 @@ public interface Copier { * @param the type of object being copied * @return a copy of the object */ - @NonNull - T copy(@NonNull T object, @NonNull ClassLoader classLoader); + T copy(T object, ClassLoader classLoader); /** @return a copy strategy that performs an identity function, for use by store-by-reference */ static Copier identity() { @@ -47,7 +44,7 @@ enum IdentityCopier implements Copier { INSTANCE; @Override - public T copy(@NonNull T object, @NonNull ClassLoader classLoader) { + public T copy(T object, ClassLoader classLoader) { return object; } } diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/event/EventTypeAwareListener.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/event/EventTypeAwareListener.java index 3f74937023..9431e0cd48 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/event/EventTypeAwareListener.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/event/EventTypeAwareListener.java @@ -22,7 +22,6 @@ import java.util.logging.Level; import java.util.logging.Logger; -import org.checkerframework.checker.nullness.qual.NonNull; import javax.cache.event.CacheEntryCreatedListener; import javax.cache.event.CacheEntryEvent; import javax.cache.event.CacheEntryExpiredListener; @@ -49,7 +48,7 @@ public EventTypeAwareListener(CacheEntryListener listener) /** Returns if the backing listener consumes this type of event. */ @SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") - public boolean isCompatible(@NonNull EventType eventType) { + public boolean isCompatible(EventType eventType) { switch (eventType) { case CREATED: return (listener instanceof CacheEntryCreatedListener); @@ -65,7 +64,7 @@ public boolean isCompatible(@NonNull EventType eventType) { /** Processes the event and logs if an exception is thrown. */ @SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") - public void dispatch(@NonNull JCacheEntryEvent event) { + public void dispatch(JCacheEntryEvent event) { try { if (event.getSource().isClosed()) { return; diff --git a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryPolicy.java b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryPolicy.java index d334692598..78f7369c36 100644 --- a/jcache/src/main/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryPolicy.java +++ b/jcache/src/main/java/com/github/benmanes/caffeine/jcache/expiry/JCacheExpiryPolicy.java @@ -20,11 +20,11 @@ import java.io.Serializable; import java.util.Objects; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import javax.cache.expiry.Duration; import javax.cache.expiry.ExpiryPolicy; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * A customized expiration policy. * @@ -37,7 +37,7 @@ public final class JCacheExpiryPolicy implements ExpiryPolicy, Serializable { private final @Nullable Duration update; private final @Nullable Duration access; - public JCacheExpiryPolicy(@NonNull Duration creation, + public JCacheExpiryPolicy(Duration creation, @Nullable Duration update, @Nullable Duration access) { this.creation = requireNonNull(creation); this.update = update;