Skip to content

Commit d74756d

Browse files
committed
Review Picnic's refaster rule suggestions
1 parent a998368 commit d74756d

78 files changed

Lines changed: 157 additions & 268 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/analysis.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
java: [ 11, 18 ]
14+
java: [ 11, 19 ]
1515
env:
1616
JAVA_VERSION: ${{ matrix.java }}
1717
steps:
@@ -20,27 +20,11 @@ jobs:
2020
with:
2121
egress-policy: audit
2222
- uses: actions/checkout@v3
23-
- name: Set up JDK ${{ matrix.java }}
24-
uses: Wandalen/wretry.action@v1.0.35
25-
timeout-minutes: 5
26-
with:
27-
action: actions/setup-java@v3
28-
with: |
29-
distribution: temurin
30-
java-version: ${{ matrix.java }}
31-
attempt_limit: 3
32-
attempt_delay: 2000
33-
- name: Setup Gradle
34-
uses: Wandalen/wretry.action@v1.0.35
35-
timeout-minutes: 5
36-
with:
37-
action: gradle/gradle-build-action@v2
38-
with: |
39-
cache-read-only: false
40-
generate-job-summary: false
41-
arguments: help --daemon --no-scan
42-
gradle-home-cache-strict-match: true
43-
attempt_limit: 3
44-
attempt_delay: 2000
4523
- name: Run analyzers
46-
run: ./.github/scripts/analyze.sh
24+
uses: ./.github/actions/run-gradle
25+
with:
26+
early-access: false
27+
java: ${{ matrix.java }}
28+
arguments: >
29+
pmdJavaPoet pmdMain pmdCodeGen pmdJmh -Dpmd
30+
spotbugsJavaPoet spotbugsMain spotbugsCodeGen spotbugsJmh -Dspotbugs

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [ push, pull_request ]
55
env:
66
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
77
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
8-
MAX_JVM: 18
8+
MAX_JVM: 19
99
EA_JVM: 20
1010

1111
jobs:

.github/workflows/dependency-check.yml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions: read-all
99
env:
1010
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
1111
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
12-
JAVA_VERSION: 18
12+
JAVA_VERSION: 19
1313

1414
jobs:
1515
dependency-check:
@@ -24,31 +24,12 @@ jobs:
2424
with:
2525
egress-policy: audit
2626
- uses: actions/checkout@v3
27-
- name: Set up JDK ${{ env.JAVA_VERSION }}
28-
uses: Wandalen/wretry.action@v1.0.35
29-
timeout-minutes: 5
30-
with:
31-
action: actions/setup-java@v3
32-
with: |
33-
cache: gradle
34-
distribution: temurin
35-
java-version: ${{ env.JAVA_VERSION }}
36-
attempt_limit: 3
37-
attempt_delay: 2000
38-
- name: Setup Gradle
39-
uses: Wandalen/wretry.action@v1.0.35
40-
timeout-minutes: 5
41-
with:
42-
action: gradle/gradle-build-action@v2
43-
with: |
44-
cache-read-only: false
45-
arguments: help --no-scan
46-
generate-job-summary: false
47-
attempt_limit: 3
48-
attempt_delay: 2000
4927
- name: Run dependency-check
50-
run: ./gradlew dependencyCheckAggregate
51-
continue-on-error: true
28+
uses: ./.github/actions/run-gradle
29+
with:
30+
early-access: false
31+
java: ${{ env.JAVA_VERSION }}
32+
arguments: dependencyCheckAggregate
5233
- name: Upload result to GitHub Code Scanning
5334
uses: github/codeql-action/upload-sarif@v2
5435
continue-on-error: true

.github/workflows/snyke.yml

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ permissions: read-all
77
env:
88
GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
99
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
10-
JAVA_VERSION: 18
10+
JAVA_VERSION: 19
1111

1212
jobs:
1313
snyke:
@@ -24,35 +24,22 @@ jobs:
2424
with:
2525
egress-policy: audit
2626
- uses: actions/checkout@v3
27-
- name: Set up JDK ${{ env.JAVA_VERSION }}
28-
uses: Wandalen/wretry.action@v1.0.35
29-
timeout-minutes: 5
30-
with:
31-
action: actions/setup-java@v3
32-
with: |
33-
distribution: temurin
34-
java-version: ${{ env.JAVA_VERSION }}
35-
attempt_limit: 3
36-
attempt_delay: 2000
37-
- name: Setup Gradle
38-
uses: Wandalen/wretry.action@v1.0.35
39-
timeout-minutes: 5
40-
with:
41-
action: gradle/gradle-build-action@v2
42-
with: |
43-
cache-read-only: false
44-
arguments: help --no-scan
45-
generate-job-summary: false
46-
attempt_limit: 3
47-
attempt_delay: 2000
4827
- name: Run Snyk test
28+
uses: ./.github/actions/run-gradle
4929
continue-on-error: true
50-
run: ./gradlew snyk-test -PsnykArgs="--sarif-file-output=snyk.sarif"
30+
with:
31+
early-access: false
32+
java: ${{ env.JAVA_VERSION }}
33+
arguments: snyk-test -PsnykArgs="--sarif-file-output=snyk.sarif"
5134
- name: Upload result to GitHub Code Scanning
5235
uses: github/codeql-action/upload-sarif@v2
5336
continue-on-error: true
5437
with:
5538
sarif_file: snyk.sarif
5639
- name: Run Snyk monitor
40+
uses: ./.github/actions/run-gradle
5741
continue-on-error: true
58-
run: ./gradlew snyk-monitor
42+
with:
43+
early-access: false
44+
java: ${{ env.JAVA_VERSION }}
45+
arguments: snyk-monitor

build.gradle

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ buildscript {
1818

1919
dependencies {
2020
classpath gradlePlugins.values()
21+
classpath platforms.collect { platform(it) }
2122

22-
configurations.each { configuration ->
23+
configurations.all { configuration ->
2324
restrictions.each { module, version ->
2425
constraints.add(configuration.name, module).version { require version }
2526
}
26-
platforms.each { dependency ->
27-
add(configuration.name, platform(dependency))
28-
}
2927
}
3028
}
3129
}
@@ -43,13 +41,10 @@ allprojects {
4341
}
4442

4543
dependencies {
46-
configurations.each { configuration ->
44+
configurations.all { configuration ->
4745
restrictions.each { module, version ->
4846
constraints.add(configuration.name, module).version { require version }
4947
}
50-
platforms.each { dependency ->
51-
add(configuration.name, platform(dependency))
52-
}
5348
}
5449
}
5550
}
@@ -72,6 +67,9 @@ subprojects {
7267
}
7368

7469
dependencies {
70+
implementation platforms.collect { platform(it) }
71+
annotationProcessor platforms.collect { platform(it) }
72+
7573
testImplementation libraries.guava
7674
testImplementation testLibraries.junit
7775
testImplementation testLibraries.truth

caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Feature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static java.util.stream.Collectors.joining;
1919

20+
import java.util.Collections;
2021
import java.util.Set;
2122

2223
import com.google.common.base.CaseFormat;
@@ -100,6 +101,6 @@ public static boolean usesMaximum(Set<Feature> features) {
100101
}
101102

102103
public static boolean usesFastPath(Set<Feature> features) {
103-
return features.stream().noneMatch(fastPathIncompatible::contains) && usesMaximum(features);
104+
return Collections.disjoint(features, fastPathIncompatible) && usesMaximum(features);
104105
}
105106
}

caffeine/src/main/java/com/github/benmanes/caffeine/cache/LocalAsyncCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ default CompletableFuture<Map<K, V>> getAll(Iterable<? extends K> keys,
160160
*/
161161
static <K, V> CompletableFuture<Map<K, V>> composeResult(Map<K, CompletableFuture<V>> futures) {
162162
if (futures.isEmpty()) {
163-
return CompletableFuture.completedFuture(Collections.emptyMap());
163+
return CompletableFuture.completedFuture(Map.of());
164164
}
165165
@SuppressWarnings("rawtypes")
166166
CompletableFuture<?>[] array = futures.values().toArray(new CompletableFuture[0]);

caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsMapTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import static com.github.benmanes.caffeine.testing.MapSubject.assertThat;
2828
import static com.google.common.base.MoreObjects.firstNonNull;
2929
import static com.google.common.collect.ImmutableMap.toImmutableMap;
30-
import static com.google.common.collect.Maps.immutableEntry;
3130
import static com.google.common.truth.Truth.assertThat;
32-
import static java.util.Map.entry;
3331
import static java.util.function.Function.identity;
3432
import static org.mockito.ArgumentMatchers.any;
3533
import static org.mockito.Mockito.times;
@@ -2567,7 +2565,7 @@ public void entrySet_contains_nullValue(Map<Int, Int> map, CacheContext context)
25672565
@Test(dataProvider = "caches")
25682566
@CacheSpec(removalListener = { Listener.DISABLED, Listener.REJECTING })
25692567
public void entrySet_contains_absent(Map<Int, Int> map, CacheContext context) {
2570-
var entry = entry(context.absentKey(), context.absentValue());
2568+
var entry = Map.entry(context.absentKey(), context.absentValue());
25712569
assertThat(map.entrySet().contains(entry)).isFalse();
25722570
}
25732571

@@ -2576,7 +2574,7 @@ public void entrySet_contains_absent(Map<Int, Int> map, CacheContext context) {
25762574
@CacheSpec(population = Population.FULL,
25772575
removalListener = { Listener.DISABLED, Listener.REJECTING })
25782576
public void entrySet_contains_present(Map<Int, Int> map, CacheContext context) {
2579-
var entry = entry(context.firstKey(), context.original().get(context.firstKey()));
2577+
var entry = Map.entry(context.firstKey(), context.original().get(context.firstKey()));
25802578
assertThat(map.entrySet().contains(entry)).isTrue();
25812579
}
25822580

@@ -2593,7 +2591,7 @@ public void entrySet_empty(Map<Int, Int> map, CacheContext context) {
25932591
@Test(dataProvider = "caches", expectedExceptions = UnsupportedOperationException.class)
25942592
public void entrySet_addIsNotSupported(Map<Int, Int> map, CacheContext context) {
25952593
try {
2596-
map.entrySet().add(immutableEntry(Int.valueOf(1), Int.valueOf(2)));
2594+
map.entrySet().add(Map.entry(Int.valueOf(1), Int.valueOf(2)));
25972595
} finally {
25982596
assertThat(map).isExhaustivelyEmpty();
25992597
}

caffeine/src/test/java/com/github/benmanes/caffeine/cache/AsyncAsMapTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@
2727
import static com.google.common.base.MoreObjects.firstNonNull;
2828
import static com.google.common.collect.ImmutableList.toImmutableList;
2929
import static com.google.common.collect.ImmutableMap.toImmutableMap;
30-
import static com.google.common.collect.Maps.immutableEntry;
3130
import static com.google.common.truth.Truth.assertThat;
32-
import static java.util.Map.entry;
3331
import static java.util.function.Function.identity;
34-
import static java.util.stream.Collectors.toUnmodifiableMap;
3532
import static org.mockito.ArgumentMatchers.any;
3633
import static org.mockito.Mockito.times;
3734
import static org.mockito.Mockito.verify;
@@ -1393,8 +1390,8 @@ public void hashCode_self(AsyncCache<Int, Int> cache, CacheContext context) {
13931390
@CacheSpec(population = Population.EMPTY,
13941391
removalListener = { Listener.DISABLED, Listener.REJECTING })
13951392
public void equalsAndHashCodeFail_empty(AsyncCache<Int, Int> cache, CacheContext context) {
1396-
var other = Stream.of(1, 2, 3)
1397-
.collect(toUnmodifiableMap(Int::valueOf, key -> Int.futureOf(-key)));
1393+
var other = Map.of(Int.valueOf(1), Int.futureOf(-1),
1394+
Int.valueOf(2), Int.futureOf(-2), Int.valueOf(3), Int.futureOf(-3));
13981395
assertThat(cache.asMap().equals(other)).isFalse();
13991396
assertThat(other.equals(cache.asMap())).isFalse();
14001397
assertThat(cache.asMap().hashCode()).isNotEqualTo(other.hashCode());
@@ -1404,10 +1401,9 @@ public void equalsAndHashCodeFail_empty(AsyncCache<Int, Int> cache, CacheContext
14041401
@Test(dataProvider = "caches")
14051402
@CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL },
14061403
removalListener = { Listener.DISABLED, Listener.REJECTING })
1407-
public void equalsAndHashCodeFail_present(
1408-
AsyncCache<Int, Int> cache, CacheContext context) {
1409-
var other = Stream.of(1, 2, 3)
1410-
.collect(toUnmodifiableMap(Int::valueOf, key -> Int.futureOf(-key)));
1404+
public void equalsAndHashCodeFail_present(AsyncCache<Int, Int> cache, CacheContext context) {
1405+
var other = Map.of(Int.valueOf(1), Int.futureOf(-1),
1406+
Int.valueOf(2), Int.futureOf(-2), Int.valueOf(3), Int.futureOf(-3));
14111407
assertThat(cache.asMap().equals(other)).isFalse();
14121408
assertThat(other.equals(cache.asMap())).isFalse();
14131409
assertThat(cache.asMap().hashCode()).isNotEqualTo(other.hashCode());
@@ -2334,7 +2330,7 @@ public void entrySet_contains_nullValue(AsyncCache<Int, Int> cache, CacheContext
23342330
@Test(dataProvider = "caches")
23352331
@CacheSpec(removalListener = { Listener.DISABLED, Listener.REJECTING })
23362332
public void entrySet_contains_absent(AsyncCache<Int, Int> cache, CacheContext context) {
2337-
var entry = entry(context.absentKey(), context.absentValue().asFuture());
2333+
var entry = Map.entry(context.absentKey(), context.absentValue().asFuture());
23382334
assertThat(cache.asMap().entrySet().contains(entry)).isFalse();
23392335
}
23402336

@@ -2343,7 +2339,7 @@ public void entrySet_contains_absent(AsyncCache<Int, Int> cache, CacheContext co
23432339
@CacheSpec(population = Population.FULL,
23442340
removalListener = { Listener.DISABLED, Listener.REJECTING })
23452341
public void entrySet_contains_present(AsyncCache<Int, Int> cache, CacheContext context) {
2346-
var entry = entry(context.firstKey(), cache.asMap().get(context.firstKey()));
2342+
var entry = Map.entry(context.firstKey(), cache.asMap().get(context.firstKey()));
23472343
assertThat(cache.asMap().entrySet().contains(entry)).isTrue();
23482344
}
23492345

@@ -2352,7 +2348,7 @@ public void entrySet_contains_present(AsyncCache<Int, Int> cache, CacheContext c
23522348
@Test(dataProvider = "caches", expectedExceptions = UnsupportedOperationException.class)
23532349
public void entrySet_addIsNotSupported(AsyncCache<Int, Int> cache, CacheContext context) {
23542350
try {
2355-
cache.asMap().entrySet().add(immutableEntry(Int.valueOf(1), Int.valueOf(2).asFuture()));
2351+
cache.asMap().entrySet().add(Map.entry(Int.valueOf(1), Int.valueOf(2).asFuture()));
23562352
} finally {
23572353
assertThat(cache).isEmpty();
23582354
}

caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import static com.google.common.collect.ImmutableList.toImmutableList;
4343
import static com.google.common.truth.Truth.assertThat;
4444
import static java.lang.Thread.State.BLOCKED;
45-
import static java.util.Map.entry;
4645
import static java.util.function.Function.identity;
4746
import static org.hamcrest.Matchers.is;
4847
import static org.mockito.ArgumentMatchers.any;
@@ -929,7 +928,7 @@ public void evict_resurrect_weight(Cache<Int, List<Int>> cache, CacheContext con
929928
ConcurrentTestHarness.execute(() -> {
930929
evictor.set(Thread.currentThread());
931930
started.set(true);
932-
cache.policy().eviction().get().setMaximum(0);
931+
cache.policy().eviction().orElseThrow().setMaximum(0);
933932
done.set(true);
934933
});
935934

@@ -943,7 +942,7 @@ public void evict_resurrect_weight(Cache<Int, List<Int>> cache, CacheContext con
943942

944943
assertThat(cache).containsEntry(key, List.of());
945944
assertThat(context).removalNotifications().withCause(REPLACED)
946-
.contains(entry(key, value)).exclusively();
945+
.contains(Map.entry(key, value)).exclusively();
947946
}
948947

949948
@Test(dataProvider = "caches")
@@ -994,14 +993,14 @@ public void evict_resurrect_expireAfterAccess(Cache<Int, Int> cache, CacheContex
994993
ConcurrentTestHarness.execute(() -> {
995994
evictor.set(Thread.currentThread());
996995
started.set(true);
997-
cache.policy().expireAfterAccess().get().setExpiresAfter(Duration.ZERO);
996+
cache.policy().expireAfterAccess().orElseThrow().setExpiresAfter(Duration.ZERO);
998997
done.set(true);
999998
});
1000999

10011000
await().untilTrue(started);
10021001
var threadState = EnumSet.of(State.BLOCKED, State.WAITING);
10031002
await().until(() -> threadState.contains(evictor.get().getState()));
1004-
cache.policy().expireAfterAccess().get().setExpiresAfter(Duration.ofHours(1));
1003+
cache.policy().expireAfterAccess().orElseThrow().setExpiresAfter(Duration.ofHours(1));
10051004
return v;
10061005
});
10071006
await().untilTrue(done);
@@ -1025,14 +1024,14 @@ public void evict_resurrect_expireAfterWrite(Cache<Int, Int> cache, CacheContext
10251024
ConcurrentTestHarness.execute(() -> {
10261025
evictor.set(Thread.currentThread());
10271026
started.set(true);
1028-
cache.policy().expireAfterWrite().get().setExpiresAfter(Duration.ZERO);
1027+
cache.policy().expireAfterWrite().orElseThrow().setExpiresAfter(Duration.ZERO);
10291028
done.set(true);
10301029
});
10311030

10321031
await().untilTrue(started);
10331032
var threadState = EnumSet.of(State.BLOCKED, State.WAITING);
10341033
await().until(() -> threadState.contains(evictor.get().getState()));
1035-
cache.policy().expireAfterWrite().get().setExpiresAfter(Duration.ofHours(1));
1034+
cache.policy().expireAfterWrite().orElseThrow().setExpiresAfter(Duration.ofHours(1));
10361035
return v;
10371036
});
10381037
await().untilTrue(done);

0 commit comments

Comments
 (0)