File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
main/java/com/datastax/oss/driver/internal/core/util/concurrent
test/java/com/datastax/oss/driver/internal/core/util/concurrent Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,10 @@ public static <T> CompletionStage<Void> allSuccessful(List<CompletionStage<T>> i
100100 } else {
101101 Throwable finalError = errors .get (0 );
102102 for (int i = 1 ; i < errors .size (); i ++) {
103- finalError .addSuppressed (errors .get (i ));
103+ Throwable suppressedError = errors .get (i );
104+ if (finalError != suppressedError ) {
105+ finalError .addSuppressed (suppressedError );
106+ }
104107 }
105108 result .completeExceptionally (finalError );
106109 }
Original file line number Diff line number Diff line change 1+ package com .datastax .oss .driver .internal .core .util .concurrent ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import java .util .Arrays ;
6+ import java .util .concurrent .CompletableFuture ;
7+ import java .util .concurrent .ExecutionException ;
8+ import java .util .concurrent .TimeUnit ;
9+ import org .junit .Test ;
10+
11+ public class CompletableFuturesTest {
12+ @ Test
13+ public void should_not_suppress_identical_exceptions () throws Exception {
14+ RuntimeException error = new RuntimeException ();
15+ CompletableFuture <Void > future1 = new CompletableFuture <>();
16+ future1 .completeExceptionally (error );
17+ CompletableFuture <Void > future2 = new CompletableFuture <>();
18+ future2 .completeExceptionally (error );
19+ try {
20+ // if timeout exception is thrown, it indicates that CompletableFutures.allSuccessful()
21+ // did not complete the returned future and potentially caller will wait infinitely
22+ CompletableFutures .allSuccessful (Arrays .asList (future1 , future2 ))
23+ .toCompletableFuture ()
24+ .get (1 , TimeUnit .SECONDS );
25+ } catch (ExecutionException e ) {
26+ assertThat (e .getCause ()).isEqualTo (error );
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments