Skip to content

Commit

Permalink
Add @CanIgnoreReturnValue annotations (#868)
Browse files Browse the repository at this point in the history
This cancels out the package-level `@CheckReturnValue` annotations
introduced in ff12385 for selected
methods.

While there, add `@CheckReturnValue` to all remaining packages.
  • Loading branch information
Stephan202 committed Feb 18, 2023
1 parent d084f2d commit 1803278
Show file tree
Hide file tree
Showing 67 changed files with 249 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.local;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.node;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
* @param <K> the type of keys maintained by this map
* @param <V> the type of mapped values
*/
@SuppressWarnings({"all", "deprecation", "JdkObsolete", "rawtypes", "serial", "unchecked",
"UnnecessaryParentheses", "UnusedNestedClass", "UnusedVariable", "YodaCondition"})
@SuppressWarnings({"all", "deprecation", "CheckReturnValue", "JdkObsolete", "rawtypes", "serial",
"unchecked", "UnnecessaryParentheses", "UnusedNestedClass", "UnusedVariable", "YodaCondition"})
public class ConcurrentHashMapV7<K, V> extends AbstractMap<K, V>
implements ConcurrentMap<K, V>, Serializable {
private static final long serialVersionUID = 7249069246763182397L;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.impl;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.sketch;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class ProfilerHook {
calls = new LongAdder();
}

@SuppressWarnings("CheckReturnValue")
public final void run() {
scheduleStatusTask();
ConcurrentTestHarness.timeTasks(NUM_THREADS, this::profile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.profiler;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
Expand Up @@ -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.CanIgnoreReturnValue;
import com.google.errorprone.annotations.FormatMethod;

/**
Expand Down Expand Up @@ -291,6 +292,7 @@ public static Caffeine<Object, Object> from(String spec) {
* @throws IllegalArgumentException if {@code initialCapacity} is negative
* @throws IllegalStateException if an initial capacity was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> initialCapacity(@NonNegative int initialCapacity) {
requireState(this.initialCapacity == UNSET_INT,
"initial capacity was already set to %s", this.initialCapacity);
Expand Down Expand Up @@ -324,6 +326,7 @@ int getInitialCapacity() {
* @return this {@code Caffeine} instance (for chaining)
* @throws NullPointerException if the specified executor is null
*/
@CanIgnoreReturnValue
public Caffeine<K, V> executor(Executor executor) {
requireState(this.executor == null, "executor was already set to %s", this.executor);
this.executor = requireNonNull(executor);
Expand Down Expand Up @@ -355,6 +358,7 @@ Executor getExecutor() {
* @return this {@code Caffeine} instance (for chaining)
* @throws NullPointerException if the specified scheduler is null
*/
@CanIgnoreReturnValue
public Caffeine<K, V> scheduler(Scheduler scheduler) {
requireState(this.scheduler == null, "scheduler was already set to %s", this.scheduler);
this.scheduler = requireNonNull(scheduler);
Expand Down Expand Up @@ -389,6 +393,7 @@ Scheduler getScheduler() {
* @throws IllegalArgumentException if {@code size} is negative
* @throws IllegalStateException if a maximum size or weight was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> maximumSize(@NonNegative long maximumSize) {
requireState(this.maximumSize == UNSET_INT,
"maximum size was already set to %s", this.maximumSize);
Expand Down Expand Up @@ -425,6 +430,7 @@ public Caffeine<K, V> maximumSize(@NonNegative long maximumSize) {
* @throws IllegalArgumentException if {@code maximumWeight} is negative
* @throws IllegalStateException if a maximum weight or size was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> maximumWeight(@NonNegative long maximumWeight) {
requireState(this.maximumWeight == UNSET_INT,
"maximum weight was already set to %s", this.maximumWeight);
Expand Down Expand Up @@ -465,6 +471,7 @@ public Caffeine<K, V> maximumWeight(@NonNegative long maximumWeight) {
* remaining configuration and cache building
* @throws IllegalStateException if a weigher was already set
*/
@CanIgnoreReturnValue
public <K1 extends K, V1 extends V> Caffeine<K1, V1> weigher(
Weigher<? super K1, ? super V1> weigher) {
requireNonNull(weigher);
Expand Down Expand Up @@ -517,6 +524,7 @@ <K1 extends K, V1 extends V> Weigher<K1, V1> getWeigher(boolean isAsync) {
* @return this {@code Caffeine} instance (for chaining)
* @throws IllegalStateException if the key strength was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> weakKeys() {
requireState(keyStrength == null, "Key strength was already set to %s", keyStrength);
keyStrength = Strength.WEAK;
Expand Down Expand Up @@ -546,6 +554,7 @@ boolean isStrongKeys() {
* @return this {@code Caffeine} instance (for chaining)
* @throws IllegalStateException if the value strength was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> weakValues() {
requireState(valueStrength == null, "Value strength was already set to %s", valueStrength);
valueStrength = Strength.WEAK;
Expand Down Expand Up @@ -582,6 +591,7 @@ boolean isWeakValues() {
* @return this {@code Caffeine} instance (for chaining)
* @throws IllegalStateException if the value strength was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> softValues() {
requireState(valueStrength == null, "Value strength was already set to %s", valueStrength);
valueStrength = Strength.SOFT;
Expand All @@ -604,6 +614,7 @@ public Caffeine<K, V> softValues() {
* @throws IllegalStateException if the time to live or variable expiration was already set
* @throws ArithmeticException for durations greater than +/- approximately 292 years
*/
@CanIgnoreReturnValue
public Caffeine<K, V> expireAfterWrite(Duration duration) {
return expireAfterWrite(saturatedToNanos(duration), TimeUnit.NANOSECONDS);
}
Expand All @@ -627,6 +638,7 @@ public Caffeine<K, V> expireAfterWrite(Duration duration) {
* @throws IllegalArgumentException if {@code duration} is negative
* @throws IllegalStateException if the time to live or variable expiration was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> expireAfterWrite(@NonNegative long duration, TimeUnit unit) {
requireState(expireAfterWriteNanos == UNSET_INT,
"expireAfterWrite was already set to %s ns", expireAfterWriteNanos);
Expand Down Expand Up @@ -663,6 +675,7 @@ boolean expiresAfterWrite() {
* @throws IllegalStateException if the time to idle or variable expiration was already set
* @throws ArithmeticException for durations greater than +/- approximately 292 years
*/
@CanIgnoreReturnValue
public Caffeine<K, V> expireAfterAccess(Duration duration) {
return expireAfterAccess(saturatedToNanos(duration), TimeUnit.NANOSECONDS);
}
Expand All @@ -689,6 +702,7 @@ public Caffeine<K, V> expireAfterAccess(Duration duration) {
* @throws IllegalArgumentException if {@code duration} is negative
* @throws IllegalStateException if the time to idle or variable expiration was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> expireAfterAccess(@NonNegative long duration, TimeUnit unit) {
requireState(expireAfterAccessNanos == UNSET_INT,
"expireAfterAccess was already set to %s ns", expireAfterAccessNanos);
Expand Down Expand Up @@ -733,6 +747,7 @@ boolean expiresAfterAccess() {
* @return this {@code Caffeine} instance (for chaining)
* @throws IllegalStateException if expiration was already set
*/
@CanIgnoreReturnValue
public <K1 extends K, V1 extends V> Caffeine<K1, V1> expireAfter(
Expiry<? super K1, ? super V1> expiry) {
requireNonNull(expiry);
Expand Down Expand Up @@ -779,6 +794,7 @@ boolean expiresVariable() {
* @throws IllegalStateException if the refresh interval was already set
* @throws ArithmeticException for durations greater than +/- approximately 292 years
*/
@CanIgnoreReturnValue
public Caffeine<K, V> refreshAfterWrite(Duration duration) {
return refreshAfterWrite(saturatedToNanos(duration), TimeUnit.NANOSECONDS);
}
Expand Down Expand Up @@ -806,6 +822,7 @@ public Caffeine<K, V> refreshAfterWrite(Duration duration) {
* @throws IllegalArgumentException if {@code duration} is zero or negative
* @throws IllegalStateException if the refresh interval was already set
*/
@CanIgnoreReturnValue
public Caffeine<K, V> refreshAfterWrite(@NonNegative long duration, TimeUnit unit) {
requireNonNull(unit);
requireState(refreshAfterWriteNanos == UNSET_INT,
Expand Down Expand Up @@ -835,6 +852,7 @@ boolean refreshAfterWrite() {
* @throws IllegalStateException if a ticker was already set
* @throws NullPointerException if the specified ticker is null
*/
@CanIgnoreReturnValue
public Caffeine<K, V> ticker(Ticker ticker) {
requireState(this.ticker == null, "Ticker was already set to %s", this.ticker);
this.ticker = requireNonNull(ticker);
Expand Down Expand Up @@ -883,6 +901,7 @@ Ticker getTicker() {
* @throws IllegalStateException if a removal listener was already set
* @throws NullPointerException if the specified removal listener is null
*/
@CanIgnoreReturnValue
public <K1 extends K, V1 extends V> Caffeine<K1, V1> evictionListener(
RemovalListener<? super K1, ? super V1> evictionListener) {
requireState(this.evictionListener == null,
Expand Down Expand Up @@ -934,6 +953,7 @@ public <K1 extends K, V1 extends V> Caffeine<K1, V1> evictionListener(
* @throws IllegalStateException if a removal listener was already set
* @throws NullPointerException if the specified removal listener is null
*/
@CanIgnoreReturnValue
public <K1 extends K, V1 extends V> Caffeine<K1, V1> removalListener(
RemovalListener<? super K1, ? super V1> removalListener) {
requireState(this.removalListener == null,
Expand Down Expand Up @@ -961,6 +981,7 @@ public <K1 extends K, V1 extends V> Caffeine<K1, V1> removalListener(
*
* @return this {@code Caffeine} instance (for chaining)
*/
@CanIgnoreReturnValue
public Caffeine<K, V> recordStats() {
requireState(this.statsCounterSupplier == null, "Statistics recording was already set");
statsCounterSupplier = ENABLED_STATS_COUNTER_SUPPLIER;
Expand All @@ -977,6 +998,7 @@ public Caffeine<K, V> recordStats() {
* @param statsCounterSupplier a supplier instance that returns a new {@link StatsCounter}
* @return this {@code Caffeine} instance (for chaining)
*/
@CanIgnoreReturnValue
public Caffeine<K, V> recordStats(Supplier<? extends StatsCounter> statsCounterSupplier) {
requireState(this.statsCounterSupplier == null, "Statistics recording was already set");
requireNonNull(statsCounterSupplier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public interface Weigher<K, V> {
*/
static <K, V> Weigher<K, V> singletonWeigher() {
@SuppressWarnings("unchecked")
Weigher<K, V> self = (Weigher<K, V>) SingletonWeigher.INSTANCE;
return self;
Weigher<K, V> instance = (Weigher<K, V>) SingletonWeigher.INSTANCE;
return instance;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.apache;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author Adam Winer
*/
@SuppressWarnings({"CheckReturnValue", "PreferJavaTimeOverload"})
@SuppressWarnings("PreferJavaTimeOverload")
public class CaffeineSpecGuavaTest extends TestCase {

public void testParse_empty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.buffer;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.issues;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.stats;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StandardSubjectBuilder;
import com.google.common.truth.Subject;
import com.google.errorprone.annotations.CanIgnoreReturnValue;

/**
* Propositions for {@link CacheContext} subjects.
Expand Down Expand Up @@ -219,30 +220,37 @@ private StatsSubject(FailureMetadata metadata, CacheContext context) {
|| (context.executorType() == CacheExecutor.DIRECT);
}

@CanIgnoreReturnValue
public StatsSubject hits(long count) {
return awaitStatistic("hitCount", CacheStats::hitCount, count);
}

@CanIgnoreReturnValue
public StatsSubject misses(long count) {
return awaitStatistic("missCount", CacheStats::missCount, count);
}

@CanIgnoreReturnValue
public StatsSubject evictions(long count) {
return awaitStatistic("evictionCount", CacheStats::evictionCount, count);
}

@CanIgnoreReturnValue
public StatsSubject evictionWeight(long count) {
return awaitStatistic("evictionWeight", CacheStats::evictionWeight, count);
}

@CanIgnoreReturnValue
public StatsSubject success(long count) {
return awaitStatistic("loadSuccessCount", CacheStats::loadSuccessCount, count);
}

@CanIgnoreReturnValue
public StatsSubject failures(long count) {
return awaitStatistic("loadFailureCount", CacheStats::loadFailureCount, count);
}

@CanIgnoreReturnValue
private StatsSubject awaitStatistic(String label,
ToLongFunction<CacheStats> supplier, long expectedValue) {
if (isDirect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.Serializable;

import com.github.benmanes.caffeine.cache.Expiry;
import com.google.errorprone.annotations.CanIgnoreReturnValue;

/**
* A builder for unit test convenience.
Expand All @@ -45,12 +46,14 @@ public static ExpiryBuilder expiringAfterCreate(long nanos) {
}

/** Sets the fixed update expiration time. */
@CanIgnoreReturnValue
public ExpiryBuilder expiringAfterUpdate(long nanos) {
updateNanos = nanos;
return this;
}

/** Sets the fixed read expiration time. */
@CanIgnoreReturnValue
public ExpiryBuilder expiringAfterRead(long nanos) {
readNanos = nanos;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.cache.testing;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.eclipse.acceptance;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.eclipse.mutable;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.eclipse;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.google;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.jsr166;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.lincheck;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.testing;

import com.google.errorprone.annotations.CheckReturnValue;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@CheckReturnValue
package com.github.benmanes.caffeine.examples.coalescing.bulkloader;

import com.google.errorprone.annotations.CheckReturnValue;
Loading

0 comments on commit 1803278

Please sign in to comment.