@@ -0,0 +1,1282 @@
+package com.millross.blog.async;%0A%0Aimport org.junit.Test;%0A%0Aimport java.util.Optional;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.concurrent.CompletionException;%0Aimport java.util.concurrent.atomic.AtomicReference;%0A%0A/**%0A * Explorations of failures at various stages in CompletionStage pipelines%0A */%0Apublic class ExceptionalPipelineTest extends CompletableFutureTestBase %7B%0A    @Test(expected = IntentionalException.class)%0A    public void exceptionCompletionFollowedByPipeline() throws Throwable %7B%0A        // This is where we'll store the exception seen in the next stage%0A        final AtomicReference%3CThrowable%3E thrownException = new AtomicReference%3C%3E(null);%0A%0A        final CompletableFuture%3CInteger%3E future = delayedExceptionalCompletion(new IntentionalException())%0A                .thenApply(i -%3E i + 1)%0A                .thenCompose(i -%3E CompletableFuture.supplyAsync(delayedValueSupplier(1), executor))%0A                .whenComplete((v, t) -%3E %7B%0A                    if (t != null) %7B%0A                        thrownException.set(t);%0A                    %7D%0A                %7D);%0A%0A        try %7B%0A            future.join();%0A        %7D catch (CompletionException ex) %7B%0A            throw (Optional.ofNullable(thrownException.get().getCause()).orElse(ex));%0A        %7D%0A    %7D%0A%0A%7D%0A

Correct thenCompose demo