From d5b75dd8bab3562fc770fdff316b08cc0c64eb09 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sat, 2 Nov 2024 10:41:19 -0700 Subject: [PATCH] upgrade errorprone-support static analysis --- .github/workflows/dependency-review.yml | 2 +- .github/workflows/qodana.yml | 2 +- .github/workflows/spelling.yml | 2 +- .../cache/LocalCacheFactoryGenerator.java | 9 ++- .../caffeine/cache/NodeFactoryGenerator.java | 9 ++- .../caffeine/cache/TimerWheelTest.java | 2 +- .../cache/testing/CacheGenerator.java | 65 ++++++++++--------- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- gradle/libs.versions.toml | 20 +++--- .../java-library.caffeine.gradle.kts | 11 ++-- .../lifecycle/testing.caffeine.gradle.kts | 4 +- .../quality/errorprone.caffeine.gradle.kts | 2 + gradle/wrapper/gradle-wrapper.properties | 2 +- .../compatibility/CacheReferencesTest.java | 5 +- .../guava/compatibility/EmptyCachesTest.java | 6 +- .../compatibility/PopulatedCachesTest.java | 6 +- .../simulator/parser/AbstractTraceReader.java | 4 +- .../cache/simulator/policy/Registry.java | 6 +- .../policy/sampled/SampledPolicy.java | 14 ++-- 24 files changed, 100 insertions(+), 83 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 720e66d9d0..8e46de5740 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -21,7 +21,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Dependency Review - uses: actions/dependency-review-action@a6993e2c61fd5dc440b409aa1d6904921c5e1894 # v4.3.5 + uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0 with: license-check: false comment-summary-in-pr: on-failure diff --git a/.github/workflows/qodana.yml b/.github/workflows/qodana.yml index 9cd2ef193d..c0f231b090 100644 --- a/.github/workflows/qodana.yml +++ b/.github/workflows/qodana.yml @@ -63,7 +63,7 @@ jobs: cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} arguments: check -x test - name: Qodana - Code Inspection - uses: JetBrains/qodana-action@4f04143e8d52028fee27c2a219c8856035094962 # v2024.2.5 + uses: JetBrains/qodana-action@31d6f3309b31c566758e1314a3d9ef0dff75ecbd # v2024.2.6 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} with: diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml index ff6a506952..4222ba5b60 100644 --- a/.github/workflows/spelling.yml +++ b/.github/workflows/spelling.yml @@ -34,4 +34,4 @@ jobs: objects.githubusercontent.com:443 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Typos - uses: crate-ci/typos@0d9e0c2c1bd7f770f6eb90f87780848ca02fc12c # v1.26.8 + uses: crate-ci/typos@d01f29c66d1bf1a08730750f61d86c210b0d039d # v1.27.0 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 c81e2061f3..d61f60c99e 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 @@ -25,7 +25,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Year; import java.time.ZoneId; import java.util.ArrayList; @@ -144,6 +143,7 @@ private NavigableMap> getClassNameToFeatures() { return classNameToFeatures; } + @SuppressWarnings("SetsImmutableEnumSetIterable") private ImmutableSet getFeatures(List combination) { var features = new LinkedHashSet(); features.add(((Boolean) combination.get(0)) ? Feature.STRONG_KEYS : Feature.WEAK_KEYS); @@ -156,6 +156,7 @@ private ImmutableSet getFeatures(List combination) { if (features.contains(Feature.MAXIMUM_WEIGHT)) { features.remove(Feature.MAXIMUM_SIZE); } + // In featureByIndex order for class naming return ImmutableSet.copyOf(features); } @@ -164,6 +165,7 @@ private Set> combinations() { return Sets.cartesianProduct(sets); } + @SuppressWarnings("SetsImmutableEnumSetIterable") private TypeSpec makeLocalCacheSpec(String className, boolean isFinal, ImmutableSet features) { TypeName superClass; @@ -174,8 +176,9 @@ private TypeSpec makeLocalCacheSpec(String className, generateFeatures = features; superClass = BOUNDED_LOCAL_CACHE; } else { + // Requires that parentFeatures is in featureByIndex order for super class naming parentFeatures = ImmutableSet.copyOf(Iterables.limit(features, features.size() - 1)); - generateFeatures = ImmutableSet.of(features.asList().get(features.size() - 1)); + generateFeatures = Sets.immutableEnumSet(features.asList().get(features.size() - 1)); superClass = ParameterizedTypeName.get(ClassName.bestGuess( encode(Feature.makeClassName(parentFeatures))), kTypeVar, vTypeVar); } @@ -208,6 +211,6 @@ private static String encode(String className) { } public static void main(String[] args) throws FormatterException, IOException { - new LocalCacheFactoryGenerator(Paths.get(args[0])).generate(); + new LocalCacheFactoryGenerator(Path.of(args[0])).generate(); } } 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 85df35469f..ae4889c348 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 @@ -25,7 +25,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Year; import java.time.ZoneId; import java.util.ArrayList; @@ -146,6 +145,7 @@ private NavigableMap> getClassNameToFeatures() { return classNameToFeatures; } + @SuppressWarnings("SetsImmutableEnumSetIterable") private ImmutableSet getFeatures(List combination) { var features = new LinkedHashSet(); features.add((Feature) combination.get(0)); @@ -158,9 +158,11 @@ private ImmutableSet getFeatures(List combination) { if (features.contains(Feature.MAXIMUM_WEIGHT)) { features.remove(Feature.MAXIMUM_SIZE); } + // In featureByIndex order for class naming return ImmutableSet.copyOf(features); } + @SuppressWarnings("SetsImmutableEnumSetIterable") private TypeSpec makeNodeSpec(String className, boolean isFinal, ImmutableSet features) { TypeName superClass; ImmutableSet parentFeatures; @@ -170,8 +172,9 @@ private TypeSpec makeNodeSpec(String className, boolean isFinal, ImmutableSet providesClock() { - return LongStream.of(CLOCKS).mapToObj(o -> (Object) o).iterator(); + return LongStream.of(CLOCKS).mapToObj(Object.class::cast).iterator(); } @DataProvider(name = "schedule") diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java index f16dc19ede..7ed1e03004 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/CacheGenerator.java @@ -89,61 +89,64 @@ public static void initialize(CacheContext context) { @SuppressWarnings("IdentityConversion") private Set> combinations() { var asyncLoader = ImmutableSet.of(true, false); - var loaders = ImmutableSet.copyOf(cacheSpec.loader()); var keys = filterTypes(options.keys(), cacheSpec.keys()); var values = filterTypes(options.values(), cacheSpec.values()); var statistics = filterTypes(options.stats(), cacheSpec.stats()); var computations = filterTypes(options.compute(), cacheSpec.compute()); + var loaders = Sets.immutableEnumSet(Arrays.asList(cacheSpec.loader())); var implementations = filterTypes(options.implementation(), cacheSpec.implementation()); if (isAsyncOnly) { values = values.contains(ReferenceType.STRONG) - ? ImmutableSet.of(ReferenceType.STRONG) + ? Sets.immutableEnumSet(ReferenceType.STRONG) : ImmutableSet.of(); - computations = Sets.intersection(computations, Set.of(Compute.ASYNC)); + computations = Sets.intersection(computations, + Sets.immutableEnumSet(Compute.ASYNC)).immutableCopy(); } - if (!isGuavaCompatible || isAsyncOnly || computations.equals(ImmutableSet.of(Compute.ASYNC))) { - implementations = Sets.difference(implementations, Set.of(Implementation.Guava)); + if (!isGuavaCompatible || isAsyncOnly + || computations.equals(Sets.immutableEnumSet(Compute.ASYNC))) { + implementations = Sets.difference(implementations, + Sets.immutableEnumSet(Implementation.Guava)).immutableCopy(); } - if (computations.equals(ImmutableSet.of(Compute.SYNC))) { + if (computations.equals(Sets.immutableEnumSet(Compute.SYNC))) { asyncLoader = ImmutableSet.of(false); } if (isLoadingOnly) { - loaders = Sets.difference(loaders, Set.of(Loader.DISABLED)).immutableCopy(); + loaders = Sets.difference(loaders, Sets.immutableEnumSet(Loader.DISABLED)).immutableCopy(); } - if (computations.isEmpty() || implementations.isEmpty() - || keys.isEmpty() || values.isEmpty()) { + if (computations.isEmpty() || implementations.isEmpty() || keys.isEmpty() || values.isEmpty()) { return ImmutableSet.of(); } return Sets.cartesianProduct( - ImmutableSet.copyOf(cacheSpec.initialCapacity()), - ImmutableSet.copyOf(statistics), - ImmutableSet.copyOf(cacheSpec.weigher()), - ImmutableSet.copyOf(cacheSpec.maximumSize()), - ImmutableSet.copyOf(cacheSpec.expiry()), - ImmutableSet.copyOf(cacheSpec.expireAfterAccess()), - ImmutableSet.copyOf(cacheSpec.expireAfterWrite()), - ImmutableSet.copyOf(cacheSpec.refreshAfterWrite()), - ImmutableSet.copyOf(keys), - ImmutableSet.copyOf(values), - ImmutableSet.copyOf(cacheSpec.executor()), - ImmutableSet.copyOf(cacheSpec.scheduler()), - ImmutableSet.copyOf(cacheSpec.removalListener()), - ImmutableSet.copyOf(cacheSpec.evictionListener()), - ImmutableSet.copyOf(cacheSpec.population()), - ImmutableSet.copyOf(asyncLoader), - ImmutableSet.copyOf(computations), - ImmutableSet.copyOf(loaders), - ImmutableSet.copyOf(implementations)); + Sets.immutableEnumSet(Arrays.asList(cacheSpec.initialCapacity())), + Sets.immutableEnumSet(statistics), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.weigher())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.maximumSize())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.expiry())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.expireAfterAccess())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.expireAfterWrite())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.refreshAfterWrite())), + Sets.immutableEnumSet(keys), + Sets.immutableEnumSet(values), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.executor())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.scheduler())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.removalListener())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.evictionListener())), + Sets.immutableEnumSet(Arrays.asList(cacheSpec.population())), + asyncLoader, + Sets.immutableEnumSet(computations), + Sets.immutableEnumSet(loaders), + Sets.immutableEnumSet(implementations)); } /** Returns the set of options filtered if a specific type is specified. */ - private static Set filterTypes(Optional type, T[] options) { + private static > ImmutableSet filterTypes(Optional type, T[] options) { return type.isPresent() - ? Sets.intersection(Set.of(options), Set.of(type.orElseThrow())) - : ImmutableSet.copyOf(options); + ? Sets.intersection(Sets.immutableEnumSet(Arrays.asList(options)), + Set.of(type.orElseThrow())).immutableCopy() + : Sets.immutableEnumSet(Arrays.asList(options)); } /** Returns a new cache context based on the combination. */ diff --git a/examples/coalescing-bulkloader-reactor/gradle/wrapper/gradle-wrapper.properties b/examples/coalescing-bulkloader-reactor/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/examples/coalescing-bulkloader-reactor/gradle/wrapper/gradle-wrapper.properties +++ b/examples/coalescing-bulkloader-reactor/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/examples/graal-native/gradle/wrapper/gradle-wrapper.properties b/examples/graal-native/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/examples/graal-native/gradle/wrapper/gradle-wrapper.properties +++ b/examples/graal-native/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/examples/hibernate/gradle/wrapper/gradle-wrapper.properties b/examples/hibernate/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/examples/hibernate/gradle/wrapper/gradle-wrapper.properties +++ b/examples/hibernate/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/examples/indexable/gradle/wrapper/gradle-wrapper.properties b/examples/indexable/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/examples/indexable/gradle/wrapper/gradle-wrapper.properties +++ b/examples/indexable/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/examples/resilience-failsafe/gradle/wrapper/gradle-wrapper.properties b/examples/resilience-failsafe/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/examples/resilience-failsafe/gradle/wrapper/gradle-wrapper.properties +++ b/examples/resilience-failsafe/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/examples/write-behind-rxjava/gradle/wrapper/gradle-wrapper.properties b/examples/write-behind-rxjava/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/examples/write-behind-rxjava/gradle/wrapper/gradle-wrapper.properties +++ b/examples/write-behind-rxjava/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8a312f2b38..9a3a8cb9f3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,11 +4,11 @@ auto-value = "1.11.0" awaitility = "4.2.2" bcel = "6.10.0" bnd = "7.0.0" -bouncycastle-jdk18on = "1.78.1" +bouncycastle-jdk18on = "1.79" cache2k = "2.6.1.Final" caffeine = "3.1.8" -checker-framework = "3.48.1" -checkstyle = "10.18.2" +checker-framework = "3.48.2" +checkstyle = "10.20.0" coherence = "22.06.2" commons-collections4 = "4.4" commons-compress = "1.27.1" @@ -19,12 +19,12 @@ commons-text = "1.12.0" concurrentlinkedhashmap = "1.4.2" config = "1.4.3" coveralls = "2.12.2" -dependency-check = "11.0.0" +dependency-check = "11.1.0" eclipse-collections = "12.0.0.M3" ehcache3 = "3.10.8" errorprone = "2.35.1" errorprone-plugin = "4.1.0" -errorprone-support = "0.18.0" +errorprone-support = "0.19.0" expiring-map = "0.5.11" fast-filter = "1.0.2" fastutil = "8.5.15" @@ -42,7 +42,7 @@ hazelcast = "5.3.7" httpclient = "4.5.14" idea = "1.1.9" jackrabbit = "1.70.0" -jackson = "2.18.0" +jackson = "2.18.1" jacoco = "0.8.12" jakarta-inject = "2.0.1" jamm = "0.4.0" @@ -68,7 +68,7 @@ kotlin = "2.0.21" lincheck = "2.34" mockito = "5.14.2" nexus-publish = "2.0.0" -nullaway = "0.12.0" +nullaway = "0.12.1" nullaway-plugin = "2.1.0" okhttp-bom = "4.12.0" okio-bom = "3.9.1" @@ -85,8 +85,8 @@ slf4j-test = "3.0.1" snakeyaml = "2.3" sonarqube = "5.1.0.4882" spotbugs = "4.8.6" -spotbugs-contrib = "7.6.5" -spotbugs-plugin = "6.0.25" +spotbugs-contrib = "7.6.6" +spotbugs-plugin = "6.0.26" stream = "2.9.8" tcache = "2.0.1" testng = "7.10.2" @@ -96,7 +96,7 @@ versions = "0.51.0" xz = "1.10" ycsb = "0.17.0" zero-allocation-hashing = "0.26ea0" -zstd = "1.5.6-6" +zstd = "1.5.6-7" [libraries] asm-bom = { module = "org.ow2.asm:asm-bom", version.ref = "asm" } diff --git a/gradle/plugins/src/main/kotlin/lifecycle/java-library.caffeine.gradle.kts b/gradle/plugins/src/main/kotlin/lifecycle/java-library.caffeine.gradle.kts index c3bb36a467..36a0ee9b47 100644 --- a/gradle/plugins/src/main/kotlin/lifecycle/java-library.caffeine.gradle.kts +++ b/gradle/plugins/src/main/kotlin/lifecycle/java-library.caffeine.gradle.kts @@ -20,6 +20,7 @@ dependencies { val javaVersion = JavaLanguageVersion.of(System.getenv("JAVA_VERSION")?.toIntOrNull() ?: 11) val javaVendor = System.getenv("JAVA_VENDOR")?.let { JvmVendorSpec.matching(it) } +val javaLtsVersion = JavaLanguageVersion.of(21) java.toolchain { languageVersion = javaVersion vendor = javaVendor @@ -33,7 +34,7 @@ tasks.withType().configureEach { javaCompiler = javaToolchains.compilerFor { // jdk 17+ is required by compiler plugins, e.g. error-prone - languageVersion = maxOf(javaVersion, JavaLanguageVersion.of(21)) + languageVersion = maxOf(javaVersion, javaLtsVersion) } options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-auxiliaryclass", "-Xlint:-classfile", @@ -88,9 +89,8 @@ tasks.withType().configureEach { use() quiet() noTimestamp() - if (javaVersion.canCompileOrRun(18)) { - addStringOption("-link-modularity-mismatch", "info") - } + addStringOption("-release", javaVersion.toString()) + addStringOption("-link-modularity-mismatch", "info") links( "https://checkerframework.org/api/", "https://errorprone.info/api/latest/", @@ -104,4 +104,7 @@ tasks.withType().configureEach { dependsOn(":caffeine:javadoc") } } + javadocTool = javaToolchains.javadocToolFor { + languageVersion = maxOf(javaVersion, javaLtsVersion) + } } diff --git a/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts b/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts index 4aeac33486..06214870cc 100644 --- a/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts +++ b/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts @@ -30,10 +30,8 @@ dependencies { tasks.withType().configureEach { inputs.property("javaVendor", java.toolchain.vendor.get().toString()) + // Use --debug-jvm to remotely attach to the test task jvmArgs("-XX:SoftRefLRUPolicyMSPerMB=0", "-XX:+EnableDynamicAgentLoading", "-Xshare:off") - if ("debug" in systemProperties) { - jvmArgs("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005") - } jvmArgs(defaultJvmArgs()) if (isCI()) { reports.junitXml.includeSystemOutLog = false diff --git a/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts b/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts index 7245ed8ec4..39abfb54ee 100644 --- a/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts +++ b/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts @@ -81,6 +81,7 @@ fun errorChecks() = listOf( fun disabledChecks() = listOf( "AvoidObjectArrays", "AndroidJdkLibsChecker", + "ConstantNaming", "IsInstanceLambdaUsage", "Java7ApiChecker", "Java8ApiChecker", @@ -88,6 +89,7 @@ fun disabledChecks() = listOf( "MissingSummary", "MultipleTopLevelClasses", "PatternMatchingInstanceof", + "Slf4jLoggerDeclaration", "StaticImport", "SuppressWarningsWithoutExplanation", "UngroupedOverloads", diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheReferencesTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheReferencesTest.java index 7660f6d2b6..3c9577afe5 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheReferencesTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/CacheReferencesTest.java @@ -28,6 +28,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; import junit.framework.TestCase; @@ -49,8 +50,8 @@ public class CacheReferencesTest extends TestCase { private static CacheBuilderFactory factoryWithAllKeyStrengths() { return new CacheBuilderFactory() - .withKeyStrengths(ImmutableSet.of(STRONG, Strength.WEAK)) - .withValueStrengths(ImmutableSet.of(STRONG, Strength.WEAK, Strength.SOFT)); + .withKeyStrengths(Sets.immutableEnumSet(STRONG, Strength.WEAK)) + .withValueStrengths(Sets.immutableEnumSet(STRONG, Strength.WEAK, Strength.SOFT)); } private static Iterable> caches() { diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/EmptyCachesTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/EmptyCachesTest.java index 3fea838d1a..16a6855035 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/EmptyCachesTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/EmptyCachesTest.java @@ -21,6 +21,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; +import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.Set; @@ -35,6 +36,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.common.testing.EqualsTester; import junit.framework.TestCase; @@ -316,8 +318,8 @@ private static Iterable> caches() { private static CacheBuilderFactory cacheFactory() { return new CacheBuilderFactory() - .withKeyStrengths(ImmutableSet.of(Strength.STRONG, Strength.WEAK)) - .withValueStrengths(ImmutableSet.copyOf(Strength.values())) + .withKeyStrengths(Sets.immutableEnumSet(Strength.STRONG, Strength.WEAK)) + .withValueStrengths(Sets.immutableEnumSet(Arrays.asList(Strength.values()))) .withConcurrencyLevels(ImmutableSet.of(1, 4, 16, 64)) .withMaximumSizes(ImmutableSet.of(0, 1, 10, 100, 1000)) .withInitialCapacities(ImmutableSet.of(0, 1, 10, 100, 1000)) diff --git a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/PopulatedCachesTest.java b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/PopulatedCachesTest.java index 1521a3c7cc..9fef4d0d7e 100644 --- a/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/PopulatedCachesTest.java +++ b/guava/src/test/java/com/github/benmanes/caffeine/guava/compatibility/PopulatedCachesTest.java @@ -22,6 +22,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -39,6 +40,7 @@ import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.common.testing.EqualsTester; import junit.framework.TestCase; @@ -314,8 +316,8 @@ private static CacheBuilderFactory cacheFactory() { // so more than (maximumSize / #segments) keys could get assigned to the same segment, which // would cause one to be evicted. return new CacheBuilderFactory() - .withKeyStrengths(ImmutableSet.of(Strength.STRONG, Strength.WEAK)) - .withValueStrengths(ImmutableSet.copyOf(Strength.values())) + .withKeyStrengths(Sets.immutableEnumSet(Strength.STRONG, Strength.WEAK)) + .withValueStrengths(Sets.immutableEnumSet(Arrays.asList(Strength.values()))) .withConcurrencyLevels(ImmutableSet.of(1, 4, 16, 64)) .withMaximumSizes(ImmutableSet.of(400, 1000)) .withInitialCapacities(ImmutableSet.of(0, 1, 10, 100, 1000)) diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java index 90a8ce37a5..24fb97216c 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java @@ -24,7 +24,7 @@ import java.io.SequenceInputStream; import java.io.UncheckedIOException; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Iterator; import java.util.List; import java.util.function.UnaryOperator; @@ -138,7 +138,7 @@ protected BufferedInputStream readInput(InputStream input) { /** Returns the input stream for the raw file. */ private InputStream openFile() throws IOException { - var file = Paths.get(filePath); + var file = Path.of(filePath); if (Files.exists(file)) { return Files.newInputStream(file); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java index 04777407e7..3e62d61ca4 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java @@ -21,6 +21,7 @@ import static java.util.Locale.US; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -77,6 +78,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.two_queue.TwoQueuePolicy; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import com.typesafe.config.Config; /** @@ -238,11 +240,11 @@ abstract static class Factory { abstract Class policyClass(); abstract Function> creator(); - Set characteristics() { + ImmutableSet characteristics() { var policySpec = policyClass().getAnnotation(PolicySpec.class); return (policySpec == null) ? ImmutableSet.of() - : ImmutableSet.copyOf(policySpec.characteristics()); + : Sets.immutableEnumSet(Arrays.asList(policySpec.characteristics())); } static Factory of(Class policyClass, Function> creator) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java index f3018d1ab3..ccc2bf4bfe 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java @@ -201,22 +201,21 @@ public enum EvictionPolicy { /** Evicts entries based on insertion order. */ FIFO { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingLong( - node -> node.insertionTime)).orElseThrow(); + return Collections.min(sample, Comparator.comparingLong(node -> node.insertionTime)); } }, /** Evicts entries based on how recently they are used, with the least recent evicted first. */ LRU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingLong(node -> node.accessTime)).orElseThrow(); + return Collections.min(sample, Comparator.comparingLong(node -> node.accessTime)); } }, /** Evicts entries based on how recently they are used, with the least recent evicted first. */ MRU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().max(Comparator.comparingLong(node -> node.accessTime)).orElseThrow(); + return Collections.max(sample, Comparator.comparingLong(node -> node.accessTime)); } }, @@ -225,7 +224,7 @@ public enum EvictionPolicy { */ LFU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingInt(node -> node.frequency)).orElseThrow(); + return Collections.min(sample, Comparator.comparingInt(node -> node.frequency)); } }, @@ -234,7 +233,7 @@ public enum EvictionPolicy { */ MFU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().max(Comparator.comparingInt(node -> node.frequency)).orElseThrow(); + return Collections.max(sample, Comparator.comparingInt(node -> node.frequency)); } }, @@ -249,8 +248,7 @@ public enum EvictionPolicy { /** Evicts entries based on how frequently they are used divided by their age. */ HYPERBOLIC { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingDouble( - node -> hyperbolic(node, tick))).orElseThrow(); + return Collections.min(sample, Comparator.comparingDouble(node -> hyperbolic(node, tick))); } double hyperbolic(Node node, long tick) { return node.frequency / (double) (tick - node.insertionTime);