From 5c4d986fb796a41a6865cfc7788aaf1d627ea841 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sun, 15 Sep 2024 01:57:30 -0700 Subject: [PATCH] enable all errorprone checks by default and resolve their nit warnings --- .github/scripts/analyze.sh | 3 +- caffeine/build.gradle.kts | 23 + .../cache/LocalCacheFactoryGenerator.java | 4 +- .../caffeine/cache/NodeFactoryGenerator.java | 4 +- .../caffeine/cache/local/AddDeques.java | 15 +- .../cache/local/AddExpireAfterAccess.java | 5 +- .../cache/local/AddKeyValueStrength.java | 6 +- .../caffeine/cache/local/AddMaximum.java | 10 +- .../cache/local/AddRemovalListener.java | 1 - .../caffeine/cache/local/AddStats.java | 6 +- .../caffeine/cache/local/AddSubtype.java | 5 +- .../caffeine/cache/node/AddConstructors.java | 22 +- .../caffeine/cache/node/AddDeques.java | 2 +- .../caffeine/cache/node/AddExpiration.java | 33 +- .../cache/node/AddFactoryMethods.java | 10 +- .../caffeine/cache/node/AddHealth.java | 15 +- .../benmanes/caffeine/cache/node/AddKey.java | 13 +- .../caffeine/cache/node/AddMaximum.java | 4 +- .../caffeine/cache/node/AddSubtype.java | 3 +- .../caffeine/cache/node/AddValue.java | 18 +- .../caffeine/cache/node/Finalize.java | 2 +- .../caffeine/cache/node/NodeContext.java | 65 +-- .../caffeine/DelegationBenchmark.java | 11 +- .../benmanes/caffeine/FactoryBenchmark.java | 10 +- .../caffeine/SlotLookupBenchmark.java | 4 +- .../caffeine/cache/BuilderBenchmark.java | 46 +- .../benmanes/caffeine/cache/CacheType.java | 2 +- .../caffeine/cache/ComputeBenchmark.java | 3 +- .../caffeine/cache/MemoryBenchmark.java | 2 +- .../caffeine/cache/TimerWheelBenchmark.java | 2 +- .../caffeine/cache/impl/HazelcastCache.java | 6 +- .../caffeine/cache/sketch/CountMinSketch.java | 3 +- .../caffeine/profiler/CacheProfiler.java | 2 +- .../caffeine/profiler/ProfilerHook.java | 2 +- .../caffeine/cache/AbstractLinkedDeque.java | 28 +- .../github/benmanes/caffeine/cache/Async.java | 4 +- .../caffeine/cache/BoundedBuffer.java | 11 +- .../caffeine/cache/BoundedLocalCache.java | 278 +++++----- .../benmanes/caffeine/cache/Caffeine.java | 35 +- .../benmanes/caffeine/cache/CaffeineSpec.java | 6 +- .../caffeine/cache/FrequencySketch.java | 12 +- .../caffeine/cache/LocalAsyncCache.java | 112 +++-- .../cache/LocalAsyncLoadingCache.java | 12 +- .../benmanes/caffeine/cache/LocalCache.java | 6 +- .../caffeine/cache/LocalCacheFactory.java | 10 +- .../caffeine/cache/LocalLoadingCache.java | 12 +- .../caffeine/cache/LocalManualCache.java | 5 +- .../cache/MpscGrowableArrayQueue.java | 111 ++-- .../github/benmanes/caffeine/cache/Node.java | 12 +- .../benmanes/caffeine/cache/NodeFactory.java | 7 +- .../benmanes/caffeine/cache/Policy.java | 3 +- .../benmanes/caffeine/cache/References.java | 4 +- .../caffeine/cache/SerializationProxy.java | 8 +- .../caffeine/cache/SnapshotEntry.java | 2 +- .../caffeine/cache/StripedBuffer.java | 24 +- .../benmanes/caffeine/cache/TimerWheel.java | 19 +- .../caffeine/cache/UnboundedLocalCache.java | 85 ++-- .../benmanes/caffeine/cache/Weigher.java | 2 +- .../caffeine/cache/stats/CacheStats.java | 2 +- .../caffeine/cache/BoundedBufferTest.java | 7 + .../caffeine/cache/BoundedLocalCacheTest.java | 72 +-- .../benmanes/caffeine/cache/CacheTest.java | 11 +- .../caffeine/cache/CaffeineSpecGuavaTest.java | 155 ++---- .../caffeine/cache/CaffeineSpecTest.java | 5 +- .../benmanes/caffeine/cache/InternerTest.java | 6 +- .../caffeine/cache/LinkedDequeTest.java | 4 +- .../caffeine/cache/LinkedDequeTests.java | 10 +- .../caffeine/cache/LocalCacheSubject.java | 10 +- .../cache/MpscGrowableArrayQueueTest.java | 8 +- .../caffeine/cache/MultiThreadedTest.java | 5 +- .../caffeine/cache/QueueSanityTest.java | 42 +- .../caffeine/cache/ReferenceTest.java | 2 +- .../caffeine/cache/RefreshAfterWriteTest.java | 2 +- .../caffeine/cache/ReserializableSubject.java | 4 +- .../caffeine/cache/TimerWheelTest.java | 6 +- .../caffeine/cache/buffer/FastFlowBuffer.java | 3 + .../cache/buffer/ManyToOneBuffer.java | 3 + .../cache/buffer/ManyToOneSpacedBuffer.java | 3 + .../caffeine/cache/buffer/TicketBuffer.java | 9 +- .../caffeine/cache/issues/Issue30Test.java | 6 +- .../caffeine/cache/issues/Issue859Test.java | 2 +- .../caffeine/cache/testing/CacheContext.java | 9 +- .../cache/testing/CacheContextSubject.java | 5 +- .../cache/testing/CacheGenerator.java | 4 +- .../caffeine/cache/testing/CacheSpec.java | 12 +- .../testing/CacheValidationListener.java | 16 +- .../testing/CaffeineCacheFromContext.java | 2 +- .../cache/testing/GuavaCacheFromContext.java | 8 +- .../ParallelMapIteratePutAcceptanceTest.java | 4 +- .../acceptance/UnifiedMapAcceptanceTest.java | 10 +- .../eclipse/mutable/MutableMapTestCase.java | 2 +- .../caffeine/jsr166/Collection8Test.java | 26 +- .../jsr166/ConcurrentHashMap8Test.java | 3 +- .../jsr166/ConcurrentHashMapTest.java | 7 +- .../caffeine/jsr166/JSR166TestCase.java | 37 +- .../benmanes/caffeine/jsr166/KeySetTest.java | 4 +- .../benmanes/caffeine/jsr166/MapTest.java | 2 +- .../caffeine/testing/CollectionSubject.java | 3 +- .../testing/ConcurrentTestHarness.java | 3 +- .../caffeine/testing/LoggingEvents.java | 4 +- .../benmanes/caffeine/testing/MapSubject.java | 1 + .../benmanes/caffeine/testing/Threads.java | 20 +- gradle/libs.versions.toml | 12 +- .../java-library.caffeine.gradle.kts | 3 +- .../quality/errorprone.caffeine.gradle.kts | 65 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- guava/build.gradle.kts | 8 + .../caffeine/guava/CaffeinatedGuavaCache.java | 10 +- .../guava/CaffeinatedGuavaLoadingCache.java | 2 +- .../caffeine/guava/GuavaMapTests.java | 2 +- .../benmanes/caffeine/guava/OSGiTest.java | 2 +- .../compatibility/CacheBuilderFactory.java | 4 +- .../compatibility/CacheBuilderGwtTest.java | 13 +- .../guava/compatibility/CacheBuilderTest.java | 252 +++------- .../compatibility/CacheEvictionTest.java | 6 +- .../compatibility/CacheExpirationTest.java | 23 +- .../guava/compatibility/CacheLoadingTest.java | 476 +++++++----------- .../guava/compatibility/CacheManualTest.java | 4 +- .../compatibility/CacheReferencesTest.java | 6 +- .../guava/compatibility/CacheTesting.java | 2 + .../guava/compatibility/EmptyCachesTest.java | 106 +--- .../LocalCacheMapComputeTest.java | 10 +- .../compatibility/LocalLoadingCacheTest.java | 7 +- .../guava/compatibility/NullCacheTest.java | 19 +- .../compatibility/PopulatedCachesTest.java | 21 +- .../compatibility/TestingCacheLoaders.java | 8 +- .../TestingRemovalListeners.java | 2 + .../guava/compatibility/TestingWeighers.java | 2 + .../caffeine/jcache/CacheFactory.java | 19 +- .../caffeine/jcache/CacheManagerImpl.java | 6 +- .../benmanes/caffeine/jcache/CacheProxy.java | 135 ++--- .../benmanes/caffeine/jcache/EntryProxy.java | 2 +- .../benmanes/caffeine/jcache/Expirable.java | 24 +- .../caffeine/jcache/LoadingCacheProxy.java | 15 +- .../configuration/CaffeineConfiguration.java | 10 +- .../configuration/TypesafeConfigurator.java | 16 +- .../caffeine/jcache/copy/AbstractCopier.java | 8 +- .../jcache/copy/JavaSerializationCopier.java | 2 +- .../jcache/event/EventDispatcher.java | 37 +- .../jcache/event/EventTypeFilter.java | 2 +- .../jcache/event/JCacheEntryEvent.java | 2 +- .../integration/JCacheLoaderAdapter.java | 6 +- .../jcache/management/JmxRegistration.java | 15 +- .../jcache/processor/EntryProcessorEntry.java | 2 +- .../jcache/spi/CaffeineCachingProvider.java | 29 +- .../caffeine/jcache/AbstractJCacheTest.java | 12 +- .../caffeine/jcache/CacheManagerTest.java | 2 +- .../caffeine/jcache/CacheProxyTest.java | 14 +- .../caffeine/jcache/JCacheProfiler.java | 1 + .../benmanes/caffeine/jcache/OSGiTest.java | 2 +- .../JCacheConfigurationTest.java | 2 +- .../copy/JavaSerializationCopierTest.java | 6 +- .../jcache/event/EventDispatcherTest.java | 4 +- .../event/EventTypeAwareListenerTest.java | 10 +- .../jcache/event/EventTypeFilterTest.java | 2 +- .../jcache/expiry/JCacheAccessExpiryTest.java | 24 +- .../expiry/JCacheCombinedExpiryTest.java | 4 +- .../expiry/JCacheCreationExpiryTest.java | 42 +- .../JCacheExpiryAndMaximumSizeTest.java | 2 +- .../jcache/expiry/JCacheUpdateExpiryTest.java | 18 +- .../jcache/integration/CacheWriterTest.java | 2 +- .../caffeine/jcache/issues/Issue1065Test.java | 2 +- .../JCacheStatisticsMXBeanTest.java | 2 +- .../processor/EntryProcessorEntryTest.java | 3 +- .../jcache/processor/EntryProcessorTest.java | 25 +- .../jcache/size/JCacheMaximumSizeTest.java | 4 +- .../jcache/size/JCacheMaximumWeightTest.java | 4 +- .../spi/CaffeineCachingProviderTest.java | 2 +- simulator/build.gradle.kts | 1 + .../caffeine/cache/simulator/Simulate.java | 14 +- .../caffeine/cache/simulator/Simulator.java | 4 +- .../admission/clairvoyant/Clairvoyant.java | 3 +- .../countmin4/ClimberResetCountMin4.java | 7 +- .../admission/countmin4/CountMin4.java | 17 +- .../countmin4/IncrementalResetCountMin4.java | 2 +- .../countmin4/IndicatorResetCountMin4.java | 2 +- .../countmin4/PeriodicResetCountMin4.java | 8 +- .../admission/countmin64/CountMin64.java | 14 +- .../countmin64/CountMin64TinyLfu.java | 4 +- .../admission/perfect/PerfectFrequency.java | 4 +- .../table/RandomRemovalFrequencyTable.java | 21 +- .../tinycache/HashFunctionParser.java | 6 +- .../admission/tinycache/TinyCache.java | 9 +- .../admission/tinycache/TinyCacheAdapter.java | 2 +- .../admission/tinycache/TinyCacheSketch.java | 16 +- .../tinycache/TinyCacheWithGhostCache.java | 12 +- .../admission/tinycache/TinySetIndexing.java | 21 +- .../membership/bloom/BloomFilter.java | 9 +- .../membership/bloom/FastFilter.java | 2 +- .../simulator/parser/AbstractTraceReader.java | 13 +- .../simulator/parser/BinaryTraceReader.java | 2 +- .../cache/simulator/parser/Rewriter.java | 5 +- .../wikipedia/WikipediaTraceReader.java | 19 +- .../cache/simulator/policy/AccessEvent.java | 2 +- .../cache/simulator/policy/PolicyActor.java | 1 + .../cache/simulator/policy/PolicyStats.java | 68 ++- .../cache/simulator/policy/Registry.java | 1 + .../simulator/policy/adaptive/ArcPolicy.java | 12 +- .../simulator/policy/adaptive/CarPolicy.java | 14 +- .../simulator/policy/adaptive/CartPolicy.java | 31 +- .../policy/greedy_dual/CampPolicy.java | 10 +- .../policy/greedy_dual/GDWheelPolicy.java | 21 +- .../policy/greedy_dual/GdsfPolicy.java | 5 +- .../policy/irr/ClockProPlusPolicy.java | 50 +- .../simulator/policy/irr/ClockProPolicy.java | 46 +- .../policy/irr/ClockProSimplePolicy.java | 31 +- .../simulator/policy/irr/DClockPolicy.java | 19 +- .../cache/simulator/policy/irr/FrdPolicy.java | 88 ++-- .../policy/irr/HillClimberFrdPolicy.java | 88 ++-- .../policy/irr/IndicatorFrdPolicy.java | 88 ++-- .../simulator/policy/irr/LirsPolicy.java | 163 +++--- .../policy/linked/FrequentlyUsedPolicy.java | 20 +- .../simulator/policy/linked/LinkedPolicy.java | 18 +- .../policy/linked/MultiQueuePolicy.java | 16 +- .../simulator/policy/linked/S4LruPolicy.java | 15 +- .../policy/linked/SegmentedLruPolicy.java | 6 +- .../simulator/policy/linked/SievePolicy.java | 3 +- .../policy/opt/ClairvoyantPolicy.java | 9 +- .../simulator/policy/opt/UnboundedPolicy.java | 2 +- .../policy/product/Cache2kPolicy.java | 4 +- .../policy/product/CaffeinePolicy.java | 2 +- .../policy/product/CoherencePolicy.java | 5 +- .../simulator/policy/product/GuavaPolicy.java | 2 +- .../policy/product/HazelcastPolicy.java | 6 +- .../policy/sampled/SampledPolicy.java | 13 +- .../simulator/policy/sketch/Indicator.java | 7 +- .../policy/sketch/WindowTinyLfuPolicy.java | 13 +- .../policy/sketch/climbing/HillClimber.java | 2 +- .../HillClimberWindowTinyLfuPolicy.java | 51 +- .../policy/sketch/climbing/gradient/Adam.java | 2 +- .../sketch/climbing/gradient/AmsGrad.java | 2 +- .../sketch/climbing/gradient/Nadam.java | 2 +- .../sketch/climbing/gradient/Stochastic.java | 2 +- .../sketch/climbing/hill/SimpleClimber.java | 2 +- .../hill/SimulatedAnnealingClimber.java | 2 +- .../climbing/inference/IndicatorClimber.java | 2 +- .../sketch/climbing/sim/MiniSimClimber.java | 15 +- .../feedback/FeedbackTinyLfuPolicy.java | 19 +- .../feedback/FeedbackWindowTinyLfuPolicy.java | 27 +- .../FullySegmentedWindowTinyLfuPolicy.java | 13 +- .../segment/LruWindowTinyLfuPolicy.java | 13 +- .../segment/RandomWindowTinyLfuPolicy.java | 8 +- .../sketch/segment/S4WindowTinyLfuPolicy.java | 20 +- .../sketch/tinycache/TinyCachePolicy.java | 2 +- .../TinyCacheWithGhostCachePolicy.java | 2 +- .../tinycache/WindowTinyCachePolicy.java | 13 +- .../policy/two_queue/S3FifoPolicy.java | 16 +- .../policy/two_queue/TuQueuePolicy.java | 12 +- .../policy/two_queue/TwoQueuePolicy.java | 5 +- .../cache/simulator/report/Metrics.java | 2 +- .../cache/simulator/report/TextReporter.java | 2 +- .../report/csv/CombinedCsvReport.java | 52 +- .../simulator/report/csv/CsvReporter.java | 4 +- .../cache/simulator/report/csv/PlotCsv.java | 24 +- .../admission/bloom/MembershipTest.java | 30 +- 255 files changed, 2322 insertions(+), 2435 deletions(-) diff --git a/.github/scripts/analyze.sh b/.github/scripts/analyze.sh index 674b3b8210..a5c57b7b9d 100755 --- a/.github/scripts/analyze.sh +++ b/.github/scripts/analyze.sh @@ -4,4 +4,5 @@ set -eux ./gradlew \ forbiddenApis -DforbiddenApis \ pmdJavaPoet pmdMain pmdCodeGen pmdJmh -Dpmd \ - spotbugsJavaPoet spotbugsMain spotbugsCodeGen spotbugsJmh -Dspotbugs + spotbugsJavaPoet spotbugsMain spotbugsCodeGen spotbugsJmh -Dspotbugs \ + "$@" diff --git a/caffeine/build.gradle.kts b/caffeine/build.gradle.kts index 30df549013..2a1a96bc5c 100644 --- a/caffeine/build.gradle.kts +++ b/caffeine/build.gradle.kts @@ -2,6 +2,7 @@ import com.google.common.collect.Sets import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis import kotlin.math.max import net.ltgt.gradle.errorprone.errorprone +import net.ltgt.gradle.nullaway.nullaway import org.gradle.api.tasks.PathSensitivity.RELATIVE import org.gradle.plugins.ide.eclipse.model.Classpath as EclipseClasspath import org.gradle.plugins.ide.eclipse.model.Library @@ -78,6 +79,13 @@ val compileCodeGenJava by tasks.existing(JavaCompile::class) { classpath = sourceSets["main"].runtimeClasspath + sourceSets["main"].output dependsOn(tasks.compileJava) options.isDebug = false + + options.errorprone { + disable("FieldMissingNullable") + disable("MissingOverride") + disable("Varifier") + nullaway.disable() + } } compileJavaPoetJava.configure { @@ -120,6 +128,21 @@ tasks.named("compileJava").configure { tasks.named("compileTestJava").configure { dependsOn(tasks.jar, compileCodeGenJava) + options.errorprone { + disable("MemberName") + disable("SystemOut") + disable("Varifier") + disable("Var") + } +} + +tasks.named("compileJmhJava").configure { + options.errorprone { + disable("MemberName") + disable("SystemOut") + disable("Varifier") + disable("Var") + } } tasks.test.configure { diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java index b9b718a1d8..c81e2061f3 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java @@ -95,8 +95,8 @@ private void generate() throws FormatterException, IOException { } private void writeJavaFile() throws IOException { - String header = Resources.toString(Resources.getResource("license.txt"), UTF_8).trim(); - ZoneId timeZone = ZoneId.of("America/Los_Angeles"); + var header = Resources.toString(Resources.getResource("license.txt"), UTF_8).trim(); + var timeZone = ZoneId.of("America/Los_Angeles"); for (TypeSpec typeSpec : factoryTypes) { JavaFile.builder(getClass().getPackageName(), typeSpec) .addFileComment(header, Year.now(timeZone)) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java index 961fd2a726..85df35469f 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java @@ -98,7 +98,7 @@ private void generate() throws FormatterException, IOException { private void writeJavaFile() throws IOException { String header = Resources.toString(Resources.getResource("license.txt"), UTF_8).trim(); - ZoneId timeZone = ZoneId.of("America/Los_Angeles"); + var timeZone = ZoneId.of("America/Los_Angeles"); for (TypeSpec node : nodeTypes) { JavaFile.builder(getClass().getPackage().getName(), node) .addFileComment(header, Year.now(timeZone)) @@ -185,7 +185,7 @@ private TypeSpec makeNodeSpec(String className, boolean isFinal, ImmutableSet> combinations() { + private static Set> combinations() { var keyStrengths = Set.of(Feature.STRONG_KEYS, Feature.WEAK_KEYS); var valueStrengths = Set.of(Feature.STRONG_VALUES, Feature.WEAK_VALUES, Feature.SOFT_VALUES); var expireAfterAccess = Set.of(false, true); diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddDeques.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddDeques.java index ebfef800d2..98eb7d5d72 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddDeques.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddDeques.java @@ -42,7 +42,7 @@ public void execute(LocalCacheContext context) { addWriteOrderDeque(context); } - private void addAccessOrderWindowDeque(LocalCacheContext context) { + private static void addAccessOrderWindowDeque(LocalCacheContext context) { if (Feature.usesAccessOrderWindowDeque(context.parentFeatures) || !Feature.usesAccessOrderWindowDeque(context.generateFeatures)) { return; @@ -52,38 +52,35 @@ private void addAccessOrderWindowDeque(LocalCacheContext context) { "this.$L = builder.evicts() || builder.expiresAfterAccess()\n? new $T()\n: null", "accessOrderWindowDeque", ACCESS_ORDER_DEQUE); addFieldAndMethod(context, ACCESS_ORDER_DEQUE, "accessOrderWindowDeque"); - context.suppressedWarnings.add("NullAway"); } - private void addAccessOrderMainDeque(LocalCacheContext context) { + private static void addAccessOrderMainDeque(LocalCacheContext context) { if (Feature.usesAccessOrderMainDeque(context.parentFeatures) || !Feature.usesAccessOrderMainDeque(context.generateFeatures)) { return; } addDeque(context, ACCESS_ORDER_DEQUE, "accessOrderProbationDeque"); addDeque(context, ACCESS_ORDER_DEQUE, "accessOrderProtectedDeque"); - context.suppressedWarnings.add("NullAway"); } - private void addWriteOrderDeque(LocalCacheContext context) { + private static void addWriteOrderDeque(LocalCacheContext context) { if (Feature.usesWriteOrderDeque(context.parentFeatures) || !Feature.usesWriteOrderDeque(context.generateFeatures)) { return; } addDeque(context, WRITE_ORDER_DEQUE, "writeOrderDeque"); - context.suppressedWarnings.add("NullAway"); } - private void addDeque(LocalCacheContext context, TypeName type, String name) { + private static void addDeque(LocalCacheContext context, TypeName type, String name) { addConstructor(context, type, name); addFieldAndMethod(context, type, name); } - private void addConstructor(LocalCacheContext context, TypeName type, String name) { + private static void addConstructor(LocalCacheContext context, TypeName type, String name) { context.constructor.addStatement("this.$L = new $T()", name, type); } - private void addFieldAndMethod(LocalCacheContext context, TypeName type, String name) { + private static void addFieldAndMethod(LocalCacheContext context, TypeName type, String name) { context.cache.addField(FieldSpec.builder(type, name, Modifier.FINAL).build()); context.cache.addMethod(MethodSpec.methodBuilder(name) .addModifiers(context.protectedFinalModifiers()) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpireAfterAccess.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpireAfterAccess.java index 8e07e9a766..45a03c8d22 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpireAfterAccess.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddExpireAfterAccess.java @@ -36,12 +36,11 @@ public boolean applies(LocalCacheContext context) { @Override public void execute(LocalCacheContext context) { - context.suppressedWarnings.add("NullAway"); variableExpiration(context); fixedExpiration(context); } - private void fixedExpiration(LocalCacheContext context) { + private static void fixedExpiration(LocalCacheContext context) { context.constructor.addStatement( "this.expiresAfterAccessNanos = builder.getExpiresAfterAccessNanos()"); context.cache.addField(FieldSpec.builder(long.class, "expiresAfterAccessNanos") @@ -63,7 +62,7 @@ private void fixedExpiration(LocalCacheContext context) { .build()); } - private void variableExpiration(LocalCacheContext context) { + private static void variableExpiration(LocalCacheContext context) { context.cache.addMethod(MethodSpec.methodBuilder("expiresVariable") .addModifiers(context.protectedFinalModifiers()) .addStatement("return (timerWheel != null)") diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddKeyValueStrength.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddKeyValueStrength.java index 225b5e4723..f111617bfc 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddKeyValueStrength.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddKeyValueStrength.java @@ -41,20 +41,20 @@ public void execute(LocalCacheContext context) { addValueStrength(context); } - private void addKeyStrength(LocalCacheContext context) { + private static void addKeyStrength(LocalCacheContext context) { if (context.generateFeatures.contains(Feature.WEAK_KEYS)) { addStrength(context, "collectKeys", "keyReferenceQueue", kRefQueueType); } } - private void addValueStrength(LocalCacheContext context) { + private static void addValueStrength(LocalCacheContext context) { if (context.generateFeatures.contains(Feature.INFIRM_VALUES)) { addStrength(context, "collectValues", "valueReferenceQueue", vRefQueueType); } } /** Adds the reference strength methods for the key or value. */ - private void addStrength(LocalCacheContext context, + private static void addStrength(LocalCacheContext context, String collectName, String queueName, TypeName type) { context.cache.addMethod(MethodSpec.methodBuilder(queueName) .addModifiers(context.protectedFinalModifiers()) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java index eecfbc6d65..4da82044da 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddMaximum.java @@ -44,7 +44,7 @@ public void execute(LocalCacheContext context) { addFrequencySketch(context); } - private void addEvicts(LocalCacheContext context) { + private static void addEvicts(LocalCacheContext context) { context.cache.addMethod(MethodSpec.methodBuilder("evicts") .addModifiers(context.protectedFinalModifiers()) .addStatement("return true") @@ -52,7 +52,7 @@ private void addEvicts(LocalCacheContext context) { .build()); } - private void addMaximumSize(LocalCacheContext context) { + private static void addMaximumSize(LocalCacheContext context) { addField(context, long.class, "maximum"); addField(context, long.class, "weightedSize"); addField(context, long.class, "windowMaximum"); @@ -61,7 +61,7 @@ private void addMaximumSize(LocalCacheContext context) { addField(context, long.class, "mainProtectedWeightedSize"); } - private void addHillClimber(LocalCacheContext context) { + private static void addHillClimber(LocalCacheContext context) { addField(context, double.class, "stepSize"); addField(context, long.class, "adjustment"); addField(context, int.class, "hitsInSample"); @@ -69,7 +69,7 @@ private void addHillClimber(LocalCacheContext context) { addField(context, double.class, "previousSampleHitRate"); } - private void addFrequencySketch(LocalCacheContext context) { + private static void addFrequencySketch(LocalCacheContext context) { context.cache.addField(FieldSpec.builder( FREQUENCY_SKETCH, "sketch", Modifier.FINAL).build()); context.constructor.addCode(CodeBlock.builder() @@ -86,7 +86,7 @@ private void addFrequencySketch(LocalCacheContext context) { .build()); } - private void addField(LocalCacheContext context, Class type, String name) { + private static void addField(LocalCacheContext context, Class type, String name) { context.cache.addField(FieldSpec.builder(type, name).build()); context.cache.addMethod(MethodSpec.methodBuilder(name) .addModifiers(context.protectedFinalModifiers()) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddRemovalListener.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddRemovalListener.java index 214dd01adc..e352954b45 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddRemovalListener.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddRemovalListener.java @@ -35,7 +35,6 @@ public boolean applies(LocalCacheContext context) { @Override public void execute(LocalCacheContext context) { - context.suppressedWarnings.add("NullAway"); context.cache.addField( FieldSpec.builder(REMOVAL_LISTENER, "removalListener", Modifier.FINAL).build()); context.constructor.addStatement("this.removalListener = builder.getRemovalListener(async)"); diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddStats.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddStats.java index 57bce1ec05..3063ca29f4 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddStats.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddStats.java @@ -41,7 +41,7 @@ public void execute(LocalCacheContext context) { addStatsCounter(context); } - private void addIsRecording(LocalCacheContext context) { + private static void addIsRecording(LocalCacheContext context) { context.cache.addMethod(MethodSpec.methodBuilder("isRecordingStats") .addModifiers(context.publicFinalModifiers()) .addStatement("return true") @@ -49,7 +49,7 @@ private void addIsRecording(LocalCacheContext context) { .build()); } - private void addStatsCounter(LocalCacheContext context) { + private static void addStatsCounter(LocalCacheContext context) { context.constructor.addStatement("this.statsCounter = builder.getStatsCounterSupplier().get()"); context.cache.addField(FieldSpec.builder( STATS_COUNTER, "statsCounter", Modifier.FINAL).build()); @@ -60,7 +60,7 @@ private void addStatsCounter(LocalCacheContext context) { .build()); } - private void addStatsTicker(LocalCacheContext context) { + private static void addStatsTicker(LocalCacheContext context) { context.cache.addMethod(MethodSpec.methodBuilder("statsTicker") .addModifiers(context.publicFinalModifiers()) .addStatement("return $T.systemTicker()", TICKER) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddSubtype.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddSubtype.java index 5c91cd3a6c..19ea059344 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddSubtype.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/local/AddSubtype.java @@ -37,7 +37,6 @@ public boolean applies(LocalCacheContext context) { @Override public void execute(LocalCacheContext context) { - context.suppressedWarnings.add("MissingOverride"); context.cache.superclass(context.superClass) .addJavadoc(getJavaDoc(context)) .addTypeVariable(kTypeVar) @@ -47,8 +46,8 @@ public void execute(LocalCacheContext context) { } } - private String getJavaDoc(LocalCacheContext context) { - StringBuilder doc = new StringBuilder(200); + private static String getJavaDoc(LocalCacheContext context) { + var doc = new StringBuilder(200); doc.append("WARNING: GENERATED CODE\n\n" + "A cache that provides the following features:\n