Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8166465

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • None
    • core-libs
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: