chia7712 commented on code in PR #17409:
URL: https://github.com/apache/kafka/pull/17409#discussion_r1807437526
##########
clients/src/main/java/org/apache/kafka/common/internals/KafkaFutureImpl.java:
##########
@@ -163,7 +163,7 @@ private void maybeThrowCancellationException(Throwable
cause) {
public T get() throws InterruptedException, ExecutionException {
try {
return completableFuture.get();
- } catch (ExecutionException e) {
+ } catch (ExecutionException | CancellationException e) {
Review Comment:
please add comment
##########
clients/src/main/java/org/apache/kafka/common/internals/KafkaFutureImpl.java:
##########
@@ -178,7 +178,7 @@ public T get(long timeout, TimeUnit unit) throws
InterruptedException, Execution
TimeoutException {
try {
return completableFuture.get(timeout, unit);
- } catch (ExecutionException e) {
+ } catch (ExecutionException | CancellationException e) {
Review Comment:
please add comment
##########
clients/src/main/java/org/apache/kafka/common/internals/KafkaFutureImpl.java:
##########
@@ -192,6 +192,14 @@ public T get(long timeout, TimeUnit unit) throws
InterruptedException, Execution
public T getNow(T valueIfAbsent) throws ExecutionException {
try {
return completableFuture.getNow(valueIfAbsent);
+ } catch (CancellationException e) {
+ // In Java 23, When a CompletableFuture is cancelled, getNow()
will throw a CompletionException wrapping a
+ // CancellationException. whereas in Java < 23, it throws a
CompletionException directly.
+ if (e.getCause() instanceof CancellationException) {
+ throw (CancellationException) e.getCause();
+ } else {
+ throw new CancellationException(e.getMessage());
Review Comment:
why not throwing `e.getCause` directly?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]