Skip to content

Commit

Permalink
upgrade errorprone static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Oct 1, 2024
1 parent af9d01e commit 3bb6639
Show file tree
Hide file tree
Showing 42 changed files with 90 additions and 71 deletions.
5 changes: 1 addition & 4 deletions caffeine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ val compileCodeGenJava by tasks.existing(JavaCompile::class) {
options.errorprone {
disable("FieldMissingNullable")
disable("MissingOverride")
disable("MemberName")
disable("Varifier")
nullaway.disable()
}
Expand Down Expand Up @@ -129,17 +130,13 @@ tasks.named<JavaCompile>("compileJava").configure {
tasks.named<JavaCompile>("compileTestJava").configure {
dependsOn(tasks.jar, compileCodeGenJava)
options.errorprone {
disable("MemberName")
disable("SystemOut")
disable("Varifier")
disable("Var")
}
}

tasks.named<JavaCompile>("compileJmhJava").configure {
options.errorprone {
disable("MemberName")
disable("SystemOut")
disable("Varifier")
disable("Var")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @author [email protected] (Ben Manes)
*/
@State(Scope.Benchmark)
@SuppressWarnings("PMD.MethodNamingConventions")
@SuppressWarnings({"MemberName", "PMD.MethodNamingConventions"})
public class DelegationBenchmark {
private static final int SIZE = (2 << 14);
private static final int MASK = SIZE - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author [email protected] (Ben Manes)
*/
@State(Scope.Benchmark)
@SuppressWarnings("PMD.MethodNamingConventions")
@SuppressWarnings({"MemberName", "PMD.MethodNamingConventions"})
public class FactoryBenchmark {
private final ReflectionFactory reflectionFactory = new ReflectionFactory();
private final MethodHandleFactory methodHandleFactory = new MethodHandleFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @author [email protected] (Ben Manes)
*/
@State(Scope.Benchmark)
@SuppressWarnings("PMD.MethodNamingConventions")
@SuppressWarnings({"MemberName", "PMD.MethodNamingConventions"})
public class SlotLookupBenchmark {
static final int SPARSE_SIZE = 2 << 14;
static final int ARENA_SIZE = 2 << 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings("PMD.MethodNamingConventions")
@SuppressWarnings({"MemberName", "PMD.MethodNamingConventions"})
public class TimeBenchmark {

@Benchmark @Threads(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author [email protected] (Ben Manes)
*/
@State(Scope.Benchmark)
@SuppressWarnings("MemberName")
public class BuilderBenchmark {
@Param BuilderType type;
Supplier<?> builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings("MemberName")
public enum CacheType {

/* --------------- Unbounded --------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
* @author [email protected] (Ben Manes)
*/
@State(Scope.Benchmark)
@SuppressWarnings({"LexicographicalAnnotationAttributeListing", "PMD.MethodNamingConventions"})
@SuppressWarnings({"LexicographicalAnnotationAttributeListing",
"MemberName", "PMD.MethodNamingConventions"})
public class ComputeBenchmark {
static final int SIZE = (2 << 14);
static final int MASK = SIZE - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
@State(Scope.Group)
@SuppressWarnings({"CanonicalAnnotationSyntax", "LexicographicalAnnotationAttributeListing",
"PMD.JUnit4TestShouldUseAfterAnnotation", "PMD.MethodNamingConventions"})
"MemberName", "PMD.JUnit4TestShouldUseAfterAnnotation", "PMD.MethodNamingConventions"})
public class GetPutBenchmark {
private static final int SIZE = (2 << 14);
private static final int MASK = SIZE - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
*
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings({"LexicographicalAnnotationAttributeListing", "PMD.MethodNamingConventions"})
@SuppressWarnings({"LexicographicalAnnotationAttributeListing",
"MemberName", "PMD.MethodNamingConventions", "SystemOut"})
public final class MemoryBenchmark {
// The number of entries added to minimize skew due to non-entry factors
static final int FUZZY_SIZE = 25_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings("MemberName")
public enum SketchType {
Flat {
@Override public <E> TinyLfuSketch<E> create(long estimatedSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final void run() {

protected abstract void profile();

@SuppressWarnings("FutureReturnValueIgnored")
@SuppressWarnings({"FutureReturnValueIgnored", "SystemOut"})
private void scheduleStatusTask() {
var stopwatch = Stopwatch.createStarted();
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public long writes() {
}

/** The namespace for field padding through inheritance. */
@SuppressWarnings("MultiVariableDeclaration")
@SuppressWarnings({"MemberName", "MultiVariableDeclaration"})
final class BBHeader {

private BBHeader() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4594,7 +4594,7 @@ private Object writeReplace() {
}

/** The namespace for field padding through inheritance. */
@SuppressWarnings("MultiVariableDeclaration")
@SuppressWarnings({"MemberName", "MultiVariableDeclaration"})
final class BLCHeader {

private BLCHeader() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ static int calculateHashMapCapacity(Iterable<?> iterable) {
: DEFAULT_INITIAL_CAPACITY;
}

/**
* Returns the number of nanoseconds of the given duration without throwing or overflowing.
* <p>
* Instead of throwing {@link ArithmeticException}, this method silently saturates to either
* {@link Long#MAX_VALUE} or {@link Long#MIN_VALUE}. This behavior can be useful when decomposing
* a duration in order to call a legacy API which requires a {@code long, TimeUnit} pair.
*/
static long toNanosSaturated(Duration duration) {
return duration.isNegative()
? (duration.compareTo(MIN_DURATION) <= 0) ? Long.MIN_VALUE : duration.toNanos()
: (duration.compareTo(MAX_DURATION) >= 0) ? Long.MAX_VALUE : duration.toNanos();
}

/**
* Constructs a new {@code Caffeine} instance with default settings, including strong keys, strong
* values, and no automatic eviction of any kind.
Expand Down Expand Up @@ -1183,19 +1196,6 @@ void requireWeightWithWeigher() {
}
}

/**
* Returns the number of nanoseconds of the given duration without throwing or overflowing.
* <p>
* Instead of throwing {@link ArithmeticException}, this method silently saturates to either
* {@link Long#MAX_VALUE} or {@link Long#MIN_VALUE}. This behavior can be useful when decomposing
* a duration in order to call a legacy API which requires a {@code long, TimeUnit} pair.
*/
static long toNanosSaturated(Duration duration) {
return duration.isNegative()
? (duration.compareTo(MIN_DURATION) <= 0) ? Long.MIN_VALUE : duration.toNanos()
: (duration.compareTo(MAX_DURATION) >= 0) ? Long.MAX_VALUE : duration.toNanos();
}

/**
* Returns a string representation for this Caffeine instance. The exact form of the returned
* string is not specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author [email protected] (Ben Manes)
*/
@RunWith(PaxExam.class)
@SuppressWarnings("MemberName")
@ExamReactorStrategy(PerMethod.class)
public final class OSGiTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void testParse_unknownKey() {
}

// Allowed by Caffeine
@SuppressWarnings("MemberName")
public void disabled_testParse_extraCommaIsInvalid() {
assertThrows(IllegalArgumentException.class, () -> parse("weakKeys,"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private void execute() {
});
}

@SuppressWarnings("SystemOut")
private void status() {
var evictionLock = local.evictionLock;
int pendingWrites;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ private List<Long> snapshot(boolean ascending) {
return snapshot;
}

@SuppressWarnings("SystemOut")
private void printTimerWheel() {
var builder = new StringBuilder();
for (int i = 0; i < timerWheel.wheel.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings("ImmutableEnumChecker")
@SuppressWarnings({"ImmutableEnumChecker", "MemberName"})
public enum BufferType {
Ticket(TicketBuffer::new),
FastFlow(FastFlowBuffer::new),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ public void testCache(Cache<Long, Long> cache, CacheContext context) {
assertThat(cache.stats().hitRate()).isGreaterThan(0.99d);
}

@SuppressWarnings("SystemOut")
static void printStats(Cache<Long, Long> cache) {
if (debug) {
System.out.printf("size %,d requests %,d hit ratio %f%n",
cache.estimatedSize(), cache.stats().requestCount(), cache.stats().hitRate());
}
}

@SuppressWarnings("SystemOut")
static void printKeys(Cache<Long, Long> cache) {
if (debug) {
Set<Long> keys = cache.policy().eviction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public CompletableFuture<String> asyncLoad(String key, Executor executor) {
return CompletableFuture.completedFuture(source.get(key));
}

@SuppressWarnings("TimeZoneUsage")
@SuppressWarnings({"SystemOut", "TimeZoneUsage"})
private void reportCacheMiss(String key) {
Instant now = Instant.now();
Instant last = lastLoad.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.github.benmanes.caffeine.testing.Awaits.await;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.Locale.US;

import java.util.Random;
Expand All @@ -30,6 +31,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalListener;
import com.github.benmanes.caffeine.testing.ConcurrentTestHarness;
import com.google.common.base.MoreObjects;

/**
* SOLR-10141: Removal listener notified with stale value
Expand Down Expand Up @@ -112,8 +114,7 @@ void test(Random r) {
}

if ((v == null) || (updateAnyway && r.nextBoolean())) {
v = new Val();
v.key = k;
v = new Val(k);
cache.put(k, v);
inserts.incrementAndGet();
}
Expand All @@ -128,11 +129,11 @@ void test(Random r) {

await().until(() -> (inserts.get() - removals.get()) == cache.estimatedSize());

System.out.printf(US, "Done!%n"
+ "entries=%,d inserts=%,d removals=%,d hits=%,d maxEntries=%,d maxObservedSize=%,d%n",
cache.estimatedSize(), inserts.get(), removals.get(),
hits.get(), maxEntries, maxObservedSize.get());
assertThat(failed).isEmpty();
var message = String.format(US,
"entries=%,d inserts=%,d removals=%,d hits=%,d maxEntries=%,d maxObservedSize=%,d%n",
cache.estimatedSize(), inserts.get(), removals.get(), hits.get(), maxEntries,
maxObservedSize.get());
assertWithMessage(message).that(failed).isEmpty();
}

@Test
Expand Down Expand Up @@ -176,8 +177,7 @@ void test(Random r) {
}

if ((v == null) || (updateAnyway && r.nextBoolean())) {
v = new Val();
v.key = k;
v = new Val(k);
cache.put(k, v);
inserts.incrementAndGet();
}
Expand All @@ -193,8 +193,19 @@ void test(Random r) {
assertThat(failed).isEmpty();
}

static class Val {
long key;
AtomicBoolean live = new AtomicBoolean(true);
static final class Val {
final AtomicBoolean live;
final long key;

Val(long key) {
this.live = new AtomicBoolean(true);
this.key = key;
}
@Override public String toString() {
return MoreObjects.toStringHelper(this)
.add("key", key)
.add("live", live.get())
.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
*
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings("ImmutableEnumChecker")
@Target(METHOD) @Retention(RUNTIME)
@SuppressWarnings({"ImmutableEnumChecker", "MemberName"})
public @interface CacheSpec {

/* --------------- Compute --------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public final class CaffeineSpecFuzzer {
// These tests require the environment variable JAZZER_FUZZ=1 to try new input arguments

@FuzzTest(maxDuration = "5m")
@SuppressWarnings({"CheckReturnValue", "PMD.EmptyCatchBlock"})
@SuppressWarnings("CheckReturnValue")
public void parse(FuzzedDataProvider data) {
try {
CaffeineSpec.parse(data.consumeRemainingAsString());
} catch (IllegalArgumentException e) { /* ignored */ }
} catch (IllegalArgumentException expected) { /* ignored */ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
*/
@SuppressWarnings({"CatchAndPrintStackTrace", "CollectionAddAllToCollectionBlock",
"CollectionForEach", "CollectionIsEmpty", "CollectionToArray", "CollectorMutability",
"LabelledBreakTarget", "MethodReferenceUsage", "MissingDefault", "MissingFail",
"MultiVariableDeclaration", "rawtypes", "ReturnValueIgnored", "try", "unchecked",
"UnnecessaryFinal", "UnnecessaryParentheses", "YodaCondition"})
"EmptyCatch", "LabelledBreakTarget", "MemberName", "MethodReferenceUsage", "MissingDefault",
"MissingFail", "MultiVariableDeclaration", "rawtypes", "ReturnValueIgnored", "SystemOut",
"try", "unchecked", "UnnecessaryFinal", "UnnecessaryParentheses", "YodaCondition"})
public class Collection8Test extends JSR166TestCase {
final CollectionImplementation impl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;

@SuppressWarnings({"IdentityConversion", "PreferredInterfaceType",
@SuppressWarnings({"EmptyCatch", "IdentityConversion", "PreferredInterfaceType",
"rawtypes", "try", "unchecked", "UnnecessaryFinal"})
public class ConcurrentHashMap8Test extends JSR166TestCase {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

import junit.framework.Test;

@SuppressWarnings({"ForEachIterable", "ModifyCollectionInEnhancedForLoop", "PreferredInterfaceType",
"rawtypes", "ReturnValueIgnored", "unchecked", "UnnecessaryFinal", "UnnecessaryParentheses"})
@SuppressWarnings({"EmptyCatch", "ForEachIterable", "MemberName",
"ModifyCollectionInEnhancedForLoop", "PreferredInterfaceType", "rawtypes",
"ReturnValueIgnored", "unchecked", "UnnecessaryFinal", "UnnecessaryParentheses"})
public class ConcurrentHashMapTest extends JSR166TestCase {
public static void main(String[] args) {
main(suite());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@
* </ul>
*/
@SuppressWarnings({"AnnotateFormatMethod", "ClassEscapesDefinedScope", "CollectionToArray",
"ConstantField", "EqualsIncompatibleType", "FunctionalInterfaceClash",
"ConstantField", "EmptyCatch", "EqualsIncompatibleType", "FunctionalInterfaceClash",
"InterruptedExceptionSwallowed", "JavaUtilDate", "JUnit3FloatingPointComparisonWithoutDelta",
"NonFinalStaticField", "NumericEquality", "rawtypes", "ReferenceEquality",
"RethrowReflectiveOperationExceptionAsLinkageError", "serial", "SwitchDefault",
"MemberName", "NonFinalStaticField", "NumericEquality", "rawtypes", "ReferenceEquality",
"RethrowReflectiveOperationExceptionAsLinkageError", "serial", "SwitchDefault", "SystemOut",
"ThreadPriorityCheck", "try", "unchecked", "UndefinedEquals", "UnnecessaryFinal"})
public class JSR166TestCase extends TestCase {
// private static final boolean useSecurityManager =
Expand Down
Loading

0 comments on commit 3bb6639

Please sign in to comment.