CompletableFuture.cancel vs Future.cancel bug?
Sergi Vladykin via Concurrency-interest <[email protected]> Thu, 20 Aug 2020 11:11:28 +0300
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CA+eZwrE8hACJmh3y3NDc_+Gyw7KOEmb7E0gzFTAGWLWzJnbzEg@mail.gmail.com> |
Hi, I noticed that the CompletableFuture.cancel method breaks the contract for Future.cancel. The spec says "This attempt will fail if the task ... has already been cancelled..." but at the same time CompletableFuture will return true even if someone else has cancelled the future. I see that it can be workarounded by completeExceptionally(new CancellationException()) but this inconsistency is neither obvious nor even documented and IMO should be fixed. To be clear I'm extending CompletableFuture.cancel with my own cancellation logic and obviously I want this logic to be executed only once thus using super.cancel() would be wrong. On another hand I want my future to behave consistently with the original CompletableFuture and of course I can emulate that but this all gets ugly... Please advise. Sergi _______________________________________________ Concurrency-interest mailing list [email protected] http://cs.oswego.edu/mailman/listinfo/concurrency-interest