From 7038cf39f67a73b9b6854a830a90580c6d3ce4af Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 3 Oct 2023 14:28:18 +0200 Subject: [PATCH] Use new List#toArray method (#779) --- .../collectors/AsyncParallelCollector.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/pivovarit/collectors/AsyncParallelCollector.java b/src/main/java/com/pivovarit/collectors/AsyncParallelCollector.java index 2bc3d25c..1937f73e 100644 --- a/src/main/java/com/pivovarit/collectors/AsyncParallelCollector.java +++ b/src/main/java/com/pivovarit/collectors/AsyncParallelCollector.java @@ -1,7 +1,6 @@ package com.pivovarit.collectors; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -79,14 +78,14 @@ public Set characteristics() { } private static CompletableFuture> combine(List> futures) { - CompletableFuture[] futuresArray = (CompletableFuture[]) futures.toArray(new CompletableFuture[0]); - CompletableFuture> combined = allOf(futuresArray) - .thenApply(__ -> Arrays.stream(futuresArray).map(CompletableFuture::join)); - - for (CompletableFuture f : futuresArray) { - f.exceptionally(ex -> { - combined.completeExceptionally(ex); - return null; + var combined = allOf(futures.toArray(CompletableFuture[]::new)) + .thenApply(__ -> futures.stream().map(CompletableFuture::join)); + + for (var future : futures) { + future.whenComplete((o, ex) -> { + if (ex != null) { + combined.completeExceptionally(ex); + } }); }