CompletableFuture already completed with an exception
Java 9 provides CompletableFuture.failedFuture(Throwable ex)
that does exactly that.
Unlike Java 9 and later, Java 8 does not provide a static factory method for this scenario. The default constructor can be used instead:
CompletableFuture<T> future = new CompletableFuture<>();
future.completeExceptionally(exception);