[concurrency-interest] CompletableFuture.whenComplete survey, pass 2

Doug Lea dl at cs.oswego.edu
Sun Dec 20 09:25:16 EST 2015

On 12/19/2015 02:41 PM, Chris Purcell wrote:
> Will you (a) open a new survey,

At this point, I think our only choice is to iterate until
we stop encountering new alternatives that we can't rule out
on other grounds. It's clear that there is no perfect policy,
but we'd still like to minimize long-term discontent.

So, please answer the new survey, before Tuesday (22 December) morning.


It simplifies question, and includes all viable options that I know of,
with very brief explanations.

Also pasted below, but don't reply to this mail with votes.

Q1. Given

   CompletableFuture<String> f1 = CompletableFuture.supplyAsync(() -> {
      if (true)
         throw new FirstException();
         return "A";

   CompletableFuture<String> f2 = f1.whenComplete((result, exception) -> {
     if (true)
        throw new SecondException();

Where "if (true)" shows the paths of interest in this question. These might 
arise from explicit error checks, programming errors, resource failures, and/or 
translated rethrows.

What should be the completed value of f2?

A. The FirstException. In other words, preserve the source outcome (only) if 
exceptional, ignoring the SecondException.

B. The FirstException, with the SecondException as its suppressed exception.  In 
other words, preserve but modify the source exception to record the SecondException.

C. The SecondException. In other words, replace the source outcome (whether it 
is exceptional or not).

D. The SecondException, with the FirstException as its suppressed exception.  In 
other words, replace the source outcome, but if exceptional, record it as a 
suppressedException of the SecondException.

E. A new CompletionException, with the FirstException as its cause and the 
SecondException as its suppressed exception. In other words, indicate that 
throwing an exception in whenComplete is a different form of error.

Q2. 2. Even if you don't prefer them, which of the above choices are acceptable?

[same options]

More information about the Concurrency-interest mailing list