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..b46052a16c 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 { 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