CompletableFuture.minimalCompletionStage().toCompletableFuture() should be non-minimal

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 9
    • Affects Version/s: None
    • Component/s: core-libs
    • None

      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.

            Assignee:
            Martin Buchholz
            Reporter:
            Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: