Skip to content

Commit e0963ed

Browse files
committed
remove unreachable code
1 parent 29bc5f1 commit e0963ed

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ githubsecuritylab
9090
gitleaks
9191
glcache
9292
gli
93+
gnubin
9394
Gnuplot
9495
Godot
9596
GPG
@@ -280,6 +281,7 @@ unconfigured
280281
unhash
281282
Uninterruptibles
282283
Unregisters
284+
usr
283285
untreeified
284286
untreeify
285287
untreeifying

caffeine/src/jcstress/java/com/github/benmanes/caffeine/cache/IntermittentNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* A stress test that simulates the behavior for {@link java.lang.ref.Reference} reads and writes in
3333
* weak or soft valued caches. The {@link Node#setValue} proactively clears the underlying referent
34-
* after updating the entry's value. This is done to assist cross-generational pollution which can
34+
* after updating the entry's value. This is done to avoid cross-generational pollution which can
3535
* cause garbage collectors to unnecessarily promote young dead objects to an old collection and
3636
* increase pause times. The {@link Node#getValue} compensates by a re-check validation to determine
3737
* if the observed null referent is due to garbage collection or a stale read. Due to referent being

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ default CompletableFuture<Map<K, V>> getAll(Iterable<? extends K> keys,
146146
Collections.unmodifiableSet(proxies.keySet()), cache().executor());
147147
return loader.handle(completer).thenCompose(ignored -> composeResult(futures));
148148
} catch (Throwable t) {
149-
completer.apply(/* result= */ null, t);
150-
throw t;
149+
throw completer.error(t);
151150
}
152151
}
153152

@@ -261,6 +260,19 @@ final class AsyncBulkCompleter<K, V> implements BiFunction<
261260
throw new CompletionException(failure);
262261
}
263262

263+
@CanIgnoreReturnValue
264+
public CompletionException error(Throwable error) {
265+
long loadTime = cache.statsTicker().read() - startTime;
266+
var failure = handleResponse(/* result= */ null, error);
267+
cache.statsCounter().recordLoadFailure(loadTime);
268+
if (failure instanceof RuntimeException) {
269+
throw (RuntimeException) failure;
270+
} else if (failure instanceof Error) {
271+
throw (Error) failure;
272+
}
273+
return new CompletionException(failure);
274+
}
275+
264276
private @Nullable Throwable handleResponse(
265277
@Nullable Map<? extends K, ? extends V> result, @Nullable Throwable error) {
266278
if (result == null) {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,7 @@ public CompletableFuture<Map<K, V>> refreshAll(Iterable<? extends K> keys) {
291291
var value = asyncCache.cache().compute(key, (ignored, currentValue) -> {
292292
var successful = asyncCache.cache().refreshes().remove(keyReference, castedFuture);
293293
if (successful && (currentValue == oldValueFuture[0])) {
294-
if (currentValue == null) {
295-
// If absent then discard the refresh and maybe notifying the listener
296-
discard[0] = (newValue != null);
297-
return null;
298-
} else if ((currentValue == newValue) || (currentValue == castedFuture)) {
294+
if ((currentValue == newValue) || (currentValue == castedFuture)) {
299295
// If the reloaded value is the same instance then no-op
300296
return currentValue;
301297
} else if (newValue == Async.getIfReady((CompletableFuture<?>) currentValue)) {

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,25 @@ public void getAllBifunction_absent_nullValue(AsyncCache<Int, Int> cache, CacheC
770770

771771
@CacheSpec
772772
@Test(dataProvider = "caches")
773-
public void getAllBifunction_absent_failure(AsyncCache<Int, Int> cache, CacheContext context) {
773+
public void getAllBifunction_absent_failure_checkedException(
774+
AsyncCache<Int, Int> cache, CacheContext context) {
775+
var future = cache.getAll(context.absentKeys(),
776+
(keys, executor) -> CompletableFuture.failedFuture(new IOException()));
777+
assertThat(future).failsWith(CompletionException.class)
778+
.hasCauseThat().isInstanceOf(IOException.class);
779+
assertThat(context).stats().hits(0).misses(context.absentKeys().size()).success(0).failures(1);
780+
assertThat(logEvents()
781+
.withMessage("Exception thrown during asynchronous load")
782+
.withThrowable(IOException.class)
783+
.withLevel(WARN)
784+
.exclusively())
785+
.hasSize(1);
786+
}
787+
788+
@CacheSpec
789+
@Test(dataProvider = "caches")
790+
public void getAllBifunction_absent_failure_runtimeException(
791+
AsyncCache<Int, Int> cache, CacheContext context) {
774792
var future = cache.getAll(context.absentKeys(),
775793
(keys, executor) -> CompletableFuture.failedFuture(new IllegalStateException()));
776794
assertThat(future).failsWith(CompletionException.class)
@@ -784,6 +802,23 @@ public void getAllBifunction_absent_failure(AsyncCache<Int, Int> cache, CacheCon
784802
.hasSize(1);
785803
}
786804

805+
@CacheSpec
806+
@Test(dataProvider = "caches")
807+
public void getAllBifunction_absent_failure_error(
808+
AsyncCache<Int, Int> cache, CacheContext context) {
809+
var future = cache.getAll(context.absentKeys(),
810+
(keys, executor) -> CompletableFuture.failedFuture(new Error()));
811+
assertThat(future).failsWith(CompletionException.class)
812+
.hasCauseThat().isInstanceOf(Error.class);
813+
assertThat(context).stats().hits(0).misses(context.absentKeys().size()).success(0).failures(1);
814+
assertThat(logEvents()
815+
.withMessage("Exception thrown during asynchronous load")
816+
.withThrowable(Error.class)
817+
.withLevel(WARN)
818+
.exclusively())
819+
.hasSize(1);
820+
}
821+
787822
@CacheSpec
788823
@Test(dataProvider = "caches")
789824
public void getAllBifunction_absent_throwsCheckedException(

gradle/config/spotbugs/exclude.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@
178178
</Match>
179179
<Match>
180180
<Class name="com.github.benmanes.caffeine.cache.LocalAsyncCache$AsyncBulkCompleter"/>
181-
<Method name="apply"/>
181+
<Or>
182+
<Method name="apply"/>
183+
<Method name="error"/>
184+
</Or>
182185
<Bug pattern="ITC_INHERITANCE_TYPE_CHECKING"/>
183186
</Match>
184187
<Match>

gradle/plugins/src/main/kotlin/analyze/jcstress.caffeine.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
22
import net.ltgt.gradle.errorprone.errorprone
3-
import org.gradle.kotlin.dsl.named
43

54
plugins {
65
id("java-library.caffeine")

0 commit comments

Comments
 (0)