Open
Description
When a ListenableFuture
is canceled and the interrupted task threw an exception,
exception thrown from the task does not seem to appear in the CancellationException
as cause or as suppressed exception.
CountDownLatch latch = new CountDownLatch(1);
ListenableFuture<Void> future = Futures.submit(() -> {
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Cancellation failed", e);
}
}, ForkJoinPool.commonPool());
Thread.sleep(1000);
future.cancel(true);
CancellationException e = assertThrows(CancellationException.class, future::get);
// expected either e.getCause() or e.getSuppressed() will carry IllegalStateException thrown from Interrupt handler
Do I have a wrong expectation and is there another way to propagate failure during cancellation to the future?