Skip to content

Commit

Permalink
Don't use CompletableFuture::join in the default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mizosoft committed Dec 20, 2024
1 parent c298105 commit 6e37bf4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import com.github.mizosoft.methanol.internal.Utils;
import com.github.mizosoft.methanol.internal.adapter.BasicAdapter;
import com.google.errorprone.annotations.CanIgnoreReturnValue;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpResponse.BodySubscriber;
Expand Down Expand Up @@ -170,7 +173,13 @@ default <T> BodySubscriber<Supplier<T>> toDeferredObject(
toObject(typeRef, mediaType),
subscriber ->
CompletableFuture.completedStage(
() -> subscriber.getBody().toCompletableFuture().join()));
() -> {
try {
return Utils.getIo(subscriber.getBody().toCompletableFuture());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.github.mizosoft.methanol.MoreBodySubscribers;
import com.github.mizosoft.methanol.TypeRef;
import com.github.mizosoft.methanol.internal.Utils;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpResponse.BodySubscriber;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -216,7 +218,13 @@ default <T> BodySubscriber<Supplier<T>> toDeferredObject(TypeRef<T> typeRef, Hin
toObject(typeRef, hints),
subscriber ->
CompletableFuture.completedStage(
() -> subscriber.getBody().toCompletableFuture().join()));
() -> {
try {
return Utils.getIo(subscriber.getBody().toCompletableFuture());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.github.mizosoft.methanol.testing.TestException;
import java.net.http.HttpResponse.BodySubscriber;
import java.net.http.HttpResponse.BodySubscribers;
import java.util.concurrent.CompletionException;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.Test;

Expand All @@ -46,8 +45,7 @@ void defaultToDeferredObjectWithExceptionalCompletion() {
verifyThat(new ReplacingDecoder("abc"))
.converting(String.class)
.withDeferredFailure(new TestException())
.failsWith(CompletionException.class)
.withCauseInstanceOf(TestException.class);
.failsWith(TestException.class);
}

private static final class ReplacingDecoder implements Decoder {
Expand Down

0 comments on commit 6e37bf4

Please sign in to comment.