completablefuture: CompletableFuture module (thenApply vs thenCompose and the serial trap, which thread runs a stage incl. join() running dependents, CompletionException wrapping, orTimeout/cancel not stopping work, allOf/anyOf with fail-fast and first-success helpers, virtual-thread timings, StructuredTaskScope preview error), 26 contract tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b3dRuKRhrHFPzWSSxr
This commit is contained in:
Ankur Mhatre
2026-11-22 18:56:47 +05:30
co-authored by Claude Sonnet 5.5
parent 59a5435825
commit 9c2ae10d7f
25 changed files with 1335 additions and 0 deletions
@@ -0,0 +1,23 @@
== 1. What does exceptionally() receive?
supplyAsync threw, exceptionally on same stage: CompletionException <- cause IllegalStateException: boom
completeExceptionally(raw), same stage: IllegalStateException: boom
completeExceptionally(raw), one stage later: CompletionException <- cause IllegalStateException: boom
== 2. What do join() and get() throw?
join(): CompletionException <- cause IllegalStateException: boom
get(): ExecutionException <- cause IllegalStateException: boom
state() = FAILED, exceptionNow() = IllegalStateException: boom
== 3. exceptionally vs handle vs whenComplete
exceptionally(ex -> -1) -> -1
handle((v, ex) -> ex==null?v:-2) -> -2
whenComplete saw: CompletionException <- cause IllegalStateException: boom
whenComplete did not recover; join(): CompletionException <- cause IllegalStateException: boom
== 4. On success, each one is a pass-through or a transformer
exceptionally on success: 7
handle on success: 14
whenComplete on success: 7
== 5. exceptionallyCompose: recover with another async call (JDK 12+)
recovered value: 99