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 eddbb92ed1..e2c5bc2d71 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 @@ -26,6 +26,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import com.google.errorprone.annotations.CheckReturnValue; + /** * A semi-persistent mapping from keys to values. Cache entries are manually added using * {@link #get(Object, Function)} or {@link #put(Object, CompletableFuture)}, and are stored in the @@ -178,6 +180,7 @@ CompletableFuture> getAll(Iterable keys, * * @return a thread-safe view of this cache supporting all of the optional {@link Map} operations */ + @CheckReturnValue ConcurrentMap> asMap(); /** @@ -188,5 +191,6 @@ CompletableFuture> getAll(Iterable keys, * * @return a thread-safe synchronous view of this cache */ + @CheckReturnValue 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 d7e269dd43..5f7902cd14 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 @@ -26,6 +26,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; +import com.google.errorprone.annotations.CheckReturnValue; + /** * Computes or retrieves values asynchronously, based on a key, for use in populating a * {@link AsyncLoadingCache}. @@ -125,6 +127,7 @@ default CompletableFuture asyncReload( * @return an asynchronous cache loader that delegates to the supplied {@code mappingFunction} * @throws NullPointerException if the mappingFunction is null */ + @CheckReturnValue static AsyncCacheLoader bulk( Function, ? extends Map> mappingFunction) { return CacheLoader.bulk(mappingFunction); @@ -146,6 +149,7 @@ static AsyncCacheLoader bulk( * @return an asynchronous cache loader that delegates to the supplied {@code mappingFunction} * @throws NullPointerException if the mappingFunction is null */ + @CheckReturnValue static AsyncCacheLoader bulk( BiFunction, ? super Executor, ? extends CompletableFuture>> 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 da2c56f92b..f16c4d4f5a 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 @@ -20,6 +20,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; +import com.google.errorprone.annotations.CheckReturnValue; + /** * 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. @@ -89,5 +91,6 @@ public interface AsyncLoadingCache synchronous(); } 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 5655b8cddb..84e2cbc470 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 @@ -26,6 +26,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import com.github.benmanes.caffeine.cache.stats.CacheStats; +import com.google.errorprone.annotations.CheckReturnValue; /** * A semi-persistent mapping from keys to values. Cache entries are manually added using @@ -180,6 +181,7 @@ Map getAll(Iterable keys, * @return the estimated number of mappings */ @NonNegative + @CheckReturnValue long estimatedSize(); /** @@ -191,6 +193,7 @@ Map getAll(Iterable keys, * * @return the current snapshot of the statistics of this cache */ + @CheckReturnValue CacheStats stats(); /** @@ -208,6 +211,7 @@ Map getAll(Iterable keys, * * @return a thread-safe view of this cache supporting all of the optional {@link Map} operations */ + @CheckReturnValue ConcurrentMap asMap(); /** @@ -223,5 +227,6 @@ Map getAll(Iterable keys, * * @return access to inspect and perform advanced operations based on the cache's characteristics */ + @CheckReturnValue 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 134bbd9e2e..6804c2b75b 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 @@ -27,6 +27,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import com.google.errorprone.annotations.CheckReturnValue; + /** * Computes or retrieves values, based on a key, for use in populating a {@link LoadingCache} or * {@link AsyncLoadingCache}. @@ -211,6 +213,7 @@ default CompletableFuture asyncReload( * @return a cache loader that delegates to the supplied {@code mappingFunction} * @throws NullPointerException if the mappingFunction is null */ + @CheckReturnValue static CacheLoader bulk( Function, ? extends Map> mappingFunction) { requireNonNull(mappingFunction); 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 b373787dee..a61f02b1a5 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 @@ -46,6 +46,7 @@ import com.github.benmanes.caffeine.cache.stats.CacheStats; import com.github.benmanes.caffeine.cache.stats.ConcurrentStatsCounter; import com.github.benmanes.caffeine.cache.stats.StatsCounter; +import com.google.errorprone.annotations.CheckReturnValue; import com.google.errorprone.annotations.FormatMethod; /** @@ -224,6 +225,7 @@ static long ceilingPowerOfTwo(long x) { * * @return a new instance with default settings */ + @CheckReturnValue public static Caffeine newBuilder() { return new Caffeine<>(); } @@ -234,6 +236,7 @@ public static Caffeine newBuilder() { * @param spec the specification to build from * @return a new instance with the specification's settings */ + @CheckReturnValue public static Caffeine from(CaffeineSpec spec) { Caffeine builder = spec.toBuilder(); builder.strictParsing = false; @@ -246,6 +249,7 @@ 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 */ + @CheckReturnValue public static Caffeine from(String spec) { return from(CaffeineSpec.parse(spec)); } @@ -1030,6 +1034,7 @@ boolean isBounded() { * @param the value type of the cache * @return a cache having the requested features */ + @CheckReturnValue public Cache build() { requireWeightWithWeigher(); requireNonLoadingCache(); @@ -1055,6 +1060,7 @@ public Cache build() { * @param the value type of the loader * @return a cache having the requested features */ + @CheckReturnValue public LoadingCache build( CacheLoader loader) { requireWeightWithWeigher(); @@ -1086,6 +1092,7 @@ public LoadingCache build( * @param the value type of the cache * @return a cache having the requested features */ + @CheckReturnValue 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"); @@ -1117,6 +1124,7 @@ public AsyncCache buildAsync() { * @param the value type of the loader * @return a cache having the requested features */ + @CheckReturnValue public AsyncLoadingCache buildAsync( CacheLoader loader) { return buildAsync((AsyncCacheLoader) loader); @@ -1140,6 +1148,7 @@ public AsyncLoadingCache buildAsync( * @param the value type of the loader * @return a cache having the requested features */ + @CheckReturnValue public AsyncLoadingCache buildAsync( AsyncCacheLoader loader) { requireState(valueStrength == null, diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java index 17ca60e70b..f967247f31 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncLoadingCacheTest.java @@ -416,14 +416,16 @@ public void asyncReload() throws Exception { assertThat(future.join(), is(-1)); } + @SuppressWarnings("CheckReturnValue") @Test(expectedExceptions = NullPointerException.class) - public void bulk_function_null_() { + public void bulk_function_null() { Function, Map> f = null; AsyncCacheLoader.bulk(f); } + @SuppressWarnings("CheckReturnValue") @Test(expectedExceptions = NullPointerException.class) - public void bulk_bifunction_null_() { + public void bulk_bifunction_null() { BiFunction, Executor, CompletableFuture>> f = null; AsyncCacheLoader.bulk(f); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java index 306c9af36f..5028adee2a 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/CaffeineTest.java @@ -44,7 +44,7 @@ * * @author ben.manes@gmail.com (Ben Manes) */ -@SuppressWarnings({"PreferJavaTimeOverload", "deprecation"}) +@SuppressWarnings({"PreferJavaTimeOverload", "deprecation", "CheckReturnValue"}) public final class CaffeineTest { @Mock StatsCounter statsCounter; @Mock Expiry expiry; diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java index 446b766deb..c753156747 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/LoadingCacheTest.java @@ -769,6 +769,7 @@ public void asyncReload() throws Exception { assertThat(future.get(), is(-1)); } + @SuppressWarnings("CheckReturnValue") @Test(expectedExceptions = NullPointerException.class) public void bulk_null() { CacheLoader.bulk(null); 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 83bbd579b9..a1441b7f5e 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 @@ -23,6 +23,7 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.errorprone.annotations.CheckReturnValue; /** * An adapter to expose a Caffeine cache through the Guava interfaces. @@ -39,6 +40,7 @@ private CaffeinatedGuava() {} * @param builder the configured cache builder * @return a cache exposed under the Guava APIs */ + @CheckReturnValue public static Cache build(Caffeine builder) { return new CaffeinatedGuavaCache<>(builder.build()); } @@ -50,6 +52,7 @@ public static Cache build(Caffeine LoadingCache build( Caffeine builder, CacheLoader loader) { @SuppressWarnings("unchecked") @@ -66,6 +69,7 @@ public static LoadingCache build( * @param loader the cache loader used to obtain new values * @return a cache exposed under the Guava APIs */ + @CheckReturnValue public static LoadingCache build( Caffeine builder, com.github.benmanes.caffeine.cache.CacheLoader loader) { diff --git a/guava/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecGuavaTest.java b/guava/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecGuavaTest.java index f249d656b6..dc101b6c85 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecGuavaTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/cache/CaffeineSpecGuavaTest.java @@ -32,7 +32,7 @@ * * @author Adam Winer */ -@SuppressWarnings("PreferJavaTimeOverload") +@SuppressWarnings({"PreferJavaTimeOverload", "CheckReturnValue"}) public class CaffeineSpecGuavaTest extends TestCase { public void testParse_empty() { diff --git a/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java b/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java index 439a2b5b22..3639198130 100644 --- a/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheBuilderTest.java @@ -238,6 +238,7 @@ public void testTimeToLive_negative_duration() { } } + @SuppressWarnings("CheckReturnValue") public void testTimeToLive_small() { CaffeinatedGuava.build(Caffeine.newBuilder() .expireAfterWrite(1, NANOSECONDS), identityLoader()); @@ -284,6 +285,7 @@ public void testTimeToIdle_negative_duration() { } } + @SuppressWarnings("CheckReturnValue") public void testTimeToIdle_small() { CaffeinatedGuava.build(Caffeine.newBuilder() .expireAfterAccess(1, NANOSECONDS), identityLoader()); @@ -312,6 +314,7 @@ public void testTimeToIdle_setTwice_duration() { } } + @SuppressWarnings("CheckReturnValue") public void testTimeToIdleAndToLive() { CaffeinatedGuava.build(Caffeine.newBuilder() .expireAfterWrite(1, NANOSECONDS)