tombentley commented on pull request #9878: URL: https://github.com/apache/kafka/pull/9878#issuecomment-762955770
@dajac there are at least two reasons why that's problematic: 1. As described by @andrasbeni in his [previous PR](https://github.com/apache/kafka/pull/5131#issuecomment-397024119) > The problem with implementing `CompletionStage` is `whenComplete`. Right now user can write `new KafkaFutureImpl<String>().thenApply(String::length)`. The lambda expression will be compiled to a `KafkaFuture.BiConsumer`. If we implement `CompletionStage`, there will be another `whenComplete` in the same class that takes `java.util.function.BiConsumer`, another SAM interface, as its parameter. That's why compiler will report ambiguity and will fail to compile above code. 2. The exception handling for some methods are just not compatible. For example, the contract of `CompletionStage` says the return value of `CompletionStage#thenApply` (and `whenComplete`) should fail with `CompletionException`: > In all other cases, if a stage's computation terminates abruptly > with an (unchecked) exception or error, then all dependent stages > requiring its completion complete exceptionally as well, with a > {@link CompletionException} holding the exception as its cause. But `KafkaFuture`'s `thenApply()` returns a `KafkaFuture` which will fail with `ExecutionException` (because `CompletionException` wasn't in Java 8 which Kafka supported at the time). (FWIW there's also a mismatch with `getNow` as it works in `CompleteableFuture` and `KafkaFutures` though that's not a method declared on `CompletionStage`). So trying to make `KafkaFuture` implement `CompleteableFuture` risks breaking users error handling code, possibly in quite subtle ways. Changes to make APIs return `CompletionStage` or `CompletableFuture` rather than `KafkaFuture` are neither source nor binary compatible and users would could have to change their error handling. So I think the only completely _safe_ option is to expose a `toCompletionStage()` method which returns the underlying `CompletableFuture`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org