-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P3
-
Affects Version/s: None
-
Component/s: core-libs
-
None
-
b138
CompletableFuture.minimalCompletionStage().toCompletableFuture() returns "this", i.e. another minimal CompletableFuture that throws UnsupportedOperationException for most operations, which is inconvenient without providing any additional safety. Users can always write their own external toCompletableFuture as follows:
static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) {
CompletableFuture<T> f = new CompletableFuture<>();
stage.handle((T t, Throwable ex) -> {
if (ex != null) f.completeExceptionally(ex);
else f.complete(t);
return null;
});
return f;
}
but this is not entirely obvious.
static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) {
CompletableFuture<T> f = new CompletableFuture<>();
stage.handle((T t, Throwable ex) -> {
if (ex != null) f.completeExceptionally(ex);
else f.complete(t);
return null;
});
return f;
}
but this is not entirely obvious.