diff --git a/src/main/java/com/pivovarit/collectors/AsyncParallelCollector.java b/src/main/java/com/pivovarit/collectors/AsyncParallelCollector.java index 2bc3d25c..cad8e269 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,11 +78,10 @@ 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)); + var combined = allOf(futures.toArray(CompletableFuture[]::new)) + .thenApply(__ -> futures.stream().map(CompletableFuture::join)); - for (CompletableFuture f : futuresArray) { + for (CompletableFuture f : futures) { f.exceptionally(ex -> { combined.completeExceptionally(ex); return null;