ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.171 by jsr166, Wed Aug 24 22:22:39 2016 UTC vs.
Revision 1.193 by jsr166, Tue Jan 30 04:07:09 2018 UTC

# Line 41 | Line 41 | import java.util.function.Function;
41   import java.util.function.Predicate;
42   import java.util.function.Supplier;
43  
44 import junit.framework.AssertionFailedError;
44   import junit.framework.Test;
45   import junit.framework.TestSuite;
46  
# Line 59 | Line 58 | public class CompletableFutureTest exten
58      void checkIncomplete(CompletableFuture<?> f) {
59          assertFalse(f.isDone());
60          assertFalse(f.isCancelled());
61 <        assertTrue(f.toString().contains("Not completed"));
61 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
62          try {
63              assertNull(f.getNow(null));
64          } catch (Throwable fail) { threadUnexpectedException(fail); }
65          try {
66 <            f.get(0L, SECONDS);
66 >            f.get(randomExpiredTimeout(), randomTimeUnit());
67              shouldThrow();
68          }
69          catch (TimeoutException success) {}
# Line 76 | Line 75 | public class CompletableFutureTest exten
75  
76          try {
77              assertEquals(value, f.join());
79        } catch (Throwable fail) { threadUnexpectedException(fail); }
80        try {
78              assertEquals(value, f.getNow(null));
82        } catch (Throwable fail) { threadUnexpectedException(fail); }
83        try {
79              assertEquals(value, f.get());
80          } catch (Throwable fail) { threadUnexpectedException(fail); }
81          assertTrue(f.isDone());
82          assertFalse(f.isCancelled());
83          assertFalse(f.isCompletedExceptionally());
84 <        assertTrue(f.toString().contains("[Completed normally]"));
84 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
85      }
86  
87      /**
88       * Returns the "raw" internal exceptional completion of f,
89       * without any additional wrapping with CompletionException.
90       */
91 <    <U> Throwable exceptionalCompletion(CompletableFuture<U> f) {
92 <        // handle (and whenComplete) can distinguish between "direct"
93 <        // and "wrapped" exceptional completion
94 <        return f.handle((U u, Throwable t) -> t).join();
91 >    Throwable exceptionalCompletion(CompletableFuture<?> f) {
92 >        // handle (and whenComplete and exceptionally) can distinguish
93 >        // between "direct" and "wrapped" exceptional completion
94 >        return f.handle((u, t) -> t).join();
95      }
96  
97      void checkCompletedExceptionally(CompletableFuture<?> f,
# Line 142 | Line 137 | public class CompletableFutureTest exten
137          assertFalse(f.isCancelled());
138          assertTrue(f.isDone());
139          assertTrue(f.isCompletedExceptionally());
140 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
140 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
141      }
142  
143      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
144          checkCompletedExceptionally(f, true,
145 <            (t) -> assertTrue(t instanceof CFException));
145 >            t -> assertTrue(t instanceof CFException));
146      }
147  
148      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
149          checkCompletedExceptionally(f, true,
150 <            (t) -> assertTrue(t instanceof CancellationException));
150 >            t -> assertTrue(t instanceof CancellationException));
151      }
152  
153      void checkCompletedWithTimeoutException(CompletableFuture<?> f) {
154          checkCompletedExceptionally(f, false,
155 <            (t) -> assertTrue(t instanceof TimeoutException));
155 >            t -> assertTrue(t instanceof TimeoutException));
156      }
157  
158      void checkCompletedWithWrappedException(CompletableFuture<?> f,
159                                              Throwable ex) {
160 <        checkCompletedExceptionally(f, true, (t) -> assertSame(t, ex));
160 >        checkCompletedExceptionally(f, true, t -> assertSame(t, ex));
161      }
162  
163      void checkCompletedExceptionally(CompletableFuture<?> f, Throwable ex) {
164 <        checkCompletedExceptionally(f, false, (t) -> assertSame(t, ex));
164 >        checkCompletedExceptionally(f, false, t -> assertSame(t, ex));
165      }
166  
167      void checkCancelled(CompletableFuture<?> f) {
# Line 197 | Line 192 | public class CompletableFutureTest exten
192          assertTrue(f.isDone());
193          assertTrue(f.isCompletedExceptionally());
194          assertTrue(f.isCancelled());
195 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
195 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
196      }
197  
198      /**
# Line 296 | Line 291 | public class CompletableFutureTest exten
291          }
292  
293          f = new CompletableFuture<>();
294 <        f.completeExceptionally(ex = new CFException());
294 >        f.completeExceptionally(new CFException());
295          f.obtrudeValue(v1);
296          checkCompletedNormally(f, v1);
297          f.obtrudeException(ex = new CFException());
# Line 333 | Line 328 | public class CompletableFutureTest exten
328      /**
329       * toString indicates current completion state
330       */
331 <    public void testToString() {
332 <        CompletableFuture<String> f;
333 <
334 <        f = new CompletableFuture<String>();
335 <        assertTrue(f.toString().contains("[Not completed]"));
331 >    public void testToString_incomplete() {
332 >        CompletableFuture<String> f = new CompletableFuture<>();
333 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
334 >        if (testImplementationDetails)
335 >            assertEquals(identityString(f) + "[Not completed]",
336 >                         f.toString());
337 >    }
338  
339 +    public void testToString_normal() {
340 +        CompletableFuture<String> f = new CompletableFuture<>();
341          assertTrue(f.complete("foo"));
342 <        assertTrue(f.toString().contains("[Completed normally]"));
342 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
343 >        if (testImplementationDetails)
344 >            assertEquals(identityString(f) + "[Completed normally]",
345 >                         f.toString());
346 >    }
347  
348 <        f = new CompletableFuture<String>();
348 >    public void testToString_exception() {
349 >        CompletableFuture<String> f = new CompletableFuture<>();
350          assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
351 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
351 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
352 >        if (testImplementationDetails)
353 >            assertTrue(f.toString().startsWith(
354 >                               identityString(f) + "[Completed exceptionally: "));
355 >    }
356  
357 +    public void testToString_cancelled() {
358          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
359 <            f = new CompletableFuture<String>();
359 >            CompletableFuture<String> f = new CompletableFuture<>();
360              assertTrue(f.cancel(mayInterruptIfRunning));
361 <            assertTrue(f.toString().contains("[Completed exceptionally]"));
361 >            assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
362 >            if (testImplementationDetails)
363 >                assertTrue(f.toString().startsWith(
364 >                                   identityString(f) + "[Completed exceptionally: "));
365          }
366      }
367  
# Line 361 | Line 373 | public class CompletableFutureTest exten
373          checkCompletedNormally(f, "test");
374      }
375  
376 <    abstract class CheckedAction {
376 >    abstract static class CheckedAction {
377          int invocationCount = 0;
378          final ExecutionMode m;
379          CheckedAction(ExecutionMode m) { this.m = m; }
# Line 373 | Line 385 | public class CompletableFutureTest exten
385          void assertInvoked() { assertEquals(1, invocationCount); }
386      }
387  
388 <    abstract class CheckedIntegerAction extends CheckedAction {
388 >    abstract static class CheckedIntegerAction extends CheckedAction {
389          Integer value;
390          CheckedIntegerAction(ExecutionMode m) { super(m); }
391          void assertValue(Integer expected) {
# Line 382 | Line 394 | public class CompletableFutureTest exten
394          }
395      }
396  
397 <    class IntegerSupplier extends CheckedAction
397 >    static class IntegerSupplier extends CheckedAction
398          implements Supplier<Integer>
399      {
400          final Integer value;
# Line 401 | Line 413 | public class CompletableFutureTest exten
413          return (x == null) ? null : x + 1;
414      }
415  
416 <    class NoopConsumer extends CheckedIntegerAction
416 >    static class NoopConsumer extends CheckedIntegerAction
417          implements Consumer<Integer>
418      {
419          NoopConsumer(ExecutionMode m) { super(m); }
# Line 411 | Line 423 | public class CompletableFutureTest exten
423          }
424      }
425  
426 <    class IncFunction extends CheckedIntegerAction
426 >    static class IncFunction extends CheckedIntegerAction
427          implements Function<Integer,Integer>
428      {
429          IncFunction(ExecutionMode m) { super(m); }
# Line 429 | Line 441 | public class CompletableFutureTest exten
441              - ((y == null) ? 99 : y.intValue());
442      }
443  
444 <    class SubtractAction extends CheckedIntegerAction
444 >    static class SubtractAction extends CheckedIntegerAction
445          implements BiConsumer<Integer, Integer>
446      {
447          SubtractAction(ExecutionMode m) { super(m); }
# Line 439 | Line 451 | public class CompletableFutureTest exten
451          }
452      }
453  
454 <    class SubtractFunction extends CheckedIntegerAction
454 >    static class SubtractFunction extends CheckedIntegerAction
455          implements BiFunction<Integer, Integer, Integer>
456      {
457          SubtractFunction(ExecutionMode m) { super(m); }
# Line 449 | Line 461 | public class CompletableFutureTest exten
461          }
462      }
463  
464 <    class Noop extends CheckedAction implements Runnable {
464 >    static class Noop extends CheckedAction implements Runnable {
465          Noop(ExecutionMode m) { super(m); }
466          public void run() {
467              invoked();
468          }
469      }
470  
471 <    class FailingSupplier extends CheckedAction
471 >    static class FailingSupplier extends CheckedAction
472          implements Supplier<Integer>
473      {
474          final CFException ex;
# Line 467 | Line 479 | public class CompletableFutureTest exten
479          }
480      }
481  
482 <    class FailingConsumer extends CheckedIntegerAction
482 >    static class FailingConsumer extends CheckedIntegerAction
483          implements Consumer<Integer>
484      {
485          final CFException ex;
# Line 479 | Line 491 | public class CompletableFutureTest exten
491          }
492      }
493  
494 <    class FailingBiConsumer extends CheckedIntegerAction
494 >    static class FailingBiConsumer extends CheckedIntegerAction
495          implements BiConsumer<Integer, Integer>
496      {
497          final CFException ex;
# Line 491 | Line 503 | public class CompletableFutureTest exten
503          }
504      }
505  
506 <    class FailingFunction extends CheckedIntegerAction
506 >    static class FailingFunction extends CheckedIntegerAction
507          implements Function<Integer, Integer>
508      {
509          final CFException ex;
# Line 503 | Line 515 | public class CompletableFutureTest exten
515          }
516      }
517  
518 <    class FailingBiFunction extends CheckedIntegerAction
518 >    static class FailingBiFunction extends CheckedIntegerAction
519          implements BiFunction<Integer, Integer, Integer>
520      {
521          final CFException ex;
# Line 515 | Line 527 | public class CompletableFutureTest exten
527          }
528      }
529  
530 <    class FailingRunnable extends CheckedAction implements Runnable {
530 >    static class FailingRunnable extends CheckedAction implements Runnable {
531          final CFException ex;
532          FailingRunnable(ExecutionMode m) { super(m); ex = new CFException(); }
533          public void run() {
# Line 524 | Line 536 | public class CompletableFutureTest exten
536          }
537      }
538  
539 <    class CompletableFutureInc extends CheckedIntegerAction
539 >    static class CompletableFutureInc extends CheckedIntegerAction
540          implements Function<Integer, CompletableFuture<Integer>>
541      {
542          CompletableFutureInc(ExecutionMode m) { super(m); }
# Line 537 | Line 549 | public class CompletableFutureTest exten
549          }
550      }
551  
552 <    class FailingCompletableFutureFunction extends CheckedIntegerAction
552 >    static class FailingCompletableFutureFunction extends CheckedIntegerAction
553          implements Function<Integer, CompletableFuture<Integer>>
554      {
555          final CFException ex;
# Line 1242 | Line 1254 | public class CompletableFutureTest exten
1254          r.assertInvoked();
1255      }}
1256  
1257 +    @SuppressWarnings("FutureReturnValueIgnored")
1258      public void testRunAsync_rejectingExecutor() {
1259          CountingRejectingExecutor e = new CountingRejectingExecutor();
1260          try {
# Line 1288 | Line 1301 | public class CompletableFutureTest exten
1301          r.assertInvoked();
1302      }}
1303  
1304 +    @SuppressWarnings("FutureReturnValueIgnored")
1305      public void testSupplyAsync_rejectingExecutor() {
1306          CountingRejectingExecutor e = new CountingRejectingExecutor();
1307          try {
# Line 2562 | Line 2576 | public class CompletableFutureTest exten
2576  
2577          // unspecified behavior - both source completions available
2578          try {
2579 <            assertEquals(null, h0.join());
2579 >            assertNull(h0.join());
2580              rs[0].assertValue(v1);
2581          } catch (CompletionException ok) {
2582              checkCompletedWithWrappedException(h0, ex);
2583              rs[0].assertNotInvoked();
2584          }
2585          try {
2586 <            assertEquals(null, h1.join());
2586 >            assertNull(h1.join());
2587              rs[1].assertValue(v1);
2588          } catch (CompletionException ok) {
2589              checkCompletedWithWrappedException(h1, ex);
2590              rs[1].assertNotInvoked();
2591          }
2592          try {
2593 <            assertEquals(null, h2.join());
2593 >            assertNull(h2.join());
2594              rs[2].assertValue(v1);
2595          } catch (CompletionException ok) {
2596              checkCompletedWithWrappedException(h2, ex);
2597              rs[2].assertNotInvoked();
2598          }
2599          try {
2600 <            assertEquals(null, h3.join());
2600 >            assertNull(h3.join());
2601              rs[3].assertValue(v1);
2602          } catch (CompletionException ok) {
2603              checkCompletedWithWrappedException(h3, ex);
# Line 2822 | Line 2836 | public class CompletableFutureTest exten
2836  
2837          // unspecified behavior - both source completions available
2838          try {
2839 <            assertEquals(null, h0.join());
2839 >            assertNull(h0.join());
2840              rs[0].assertInvoked();
2841          } catch (CompletionException ok) {
2842              checkCompletedWithWrappedException(h0, ex);
2843              rs[0].assertNotInvoked();
2844          }
2845          try {
2846 <            assertEquals(null, h1.join());
2846 >            assertNull(h1.join());
2847              rs[1].assertInvoked();
2848          } catch (CompletionException ok) {
2849              checkCompletedWithWrappedException(h1, ex);
2850              rs[1].assertNotInvoked();
2851          }
2852          try {
2853 <            assertEquals(null, h2.join());
2853 >            assertNull(h2.join());
2854              rs[2].assertInvoked();
2855          } catch (CompletionException ok) {
2856              checkCompletedWithWrappedException(h2, ex);
2857              rs[2].assertNotInvoked();
2858          }
2859          try {
2860 <            assertEquals(null, h3.join());
2860 >            assertNull(h3.join());
2861              rs[3].assertInvoked();
2862          } catch (CompletionException ok) {
2863              checkCompletedWithWrappedException(h3, ex);
# Line 3238 | Line 3252 | public class CompletableFutureTest exten
3252      /**
3253       * Completion methods throw NullPointerException with null arguments
3254       */
3255 +    @SuppressWarnings("FutureReturnValueIgnored")
3256      public void testNPE() {
3257          CompletableFuture<Integer> f = new CompletableFuture<>();
3258          CompletableFuture<Integer> g = new CompletableFuture<>();
# Line 3257 | Line 3272 | public class CompletableFutureTest exten
3272  
3273              () -> f.thenApply(null),
3274              () -> f.thenApplyAsync(null),
3275 <            () -> f.thenApplyAsync((x) -> x, null),
3275 >            () -> f.thenApplyAsync(x -> x, null),
3276              () -> f.thenApplyAsync(null, exec),
3277  
3278              () -> f.thenAccept(null),
3279              () -> f.thenAcceptAsync(null),
3280 <            () -> f.thenAcceptAsync((x) -> {} , null),
3280 >            () -> f.thenAcceptAsync(x -> {} , null),
3281              () -> f.thenAcceptAsync(null, exec),
3282  
3283              () -> f.thenRun(null),
# Line 3297 | Line 3312 | public class CompletableFutureTest exten
3312              () -> f.applyToEither(g, null),
3313              () -> f.applyToEitherAsync(g, null),
3314              () -> f.applyToEitherAsync(g, null, exec),
3315 <            () -> f.applyToEither(nullFuture, (x) -> x),
3316 <            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3317 <            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3318 <            () -> f.applyToEitherAsync(g, (x) -> x, null),
3315 >            () -> f.applyToEither(nullFuture, x -> x),
3316 >            () -> f.applyToEitherAsync(nullFuture, x -> x),
3317 >            () -> f.applyToEitherAsync(nullFuture, x -> x, exec),
3318 >            () -> f.applyToEitherAsync(g, x -> x, null),
3319  
3320              () -> f.acceptEither(g, null),
3321              () -> f.acceptEitherAsync(g, null),
3322              () -> f.acceptEitherAsync(g, null, exec),
3323 <            () -> f.acceptEither(nullFuture, (x) -> {}),
3324 <            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3325 <            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3326 <            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3323 >            () -> f.acceptEither(nullFuture, x -> {}),
3324 >            () -> f.acceptEitherAsync(nullFuture, x -> {}),
3325 >            () -> f.acceptEitherAsync(nullFuture, x -> {}, exec),
3326 >            () -> f.acceptEitherAsync(g, x -> {}, null),
3327  
3328              () -> f.runAfterEither(g, null),
3329              () -> f.runAfterEitherAsync(g, null),
# Line 3374 | Line 3389 | public class CompletableFutureTest exten
3389          for (CompletableFuture<Integer> src : srcs) {
3390              List<CompletableFuture<?>> fs = new ArrayList<>();
3391              fs.add(src.thenRunAsync(() -> {}, e));
3392 <            fs.add(src.thenAcceptAsync((z) -> {}, e));
3393 <            fs.add(src.thenApplyAsync((z) -> z, e));
3392 >            fs.add(src.thenAcceptAsync(z -> {}, e));
3393 >            fs.add(src.thenApplyAsync(z -> z, e));
3394  
3395              fs.add(src.thenCombineAsync(src, (x, y) -> x, e));
3396              fs.add(src.thenAcceptBothAsync(src, (x, y) -> {}, e));
3397              fs.add(src.runAfterBothAsync(src, () -> {}, e));
3398  
3399 <            fs.add(src.applyToEitherAsync(src, (z) -> z, e));
3400 <            fs.add(src.acceptEitherAsync(src, (z) -> {}, e));
3399 >            fs.add(src.applyToEitherAsync(src, z -> z, e));
3400 >            fs.add(src.acceptEitherAsync(src, z -> {}, e));
3401              fs.add(src.runAfterEitherAsync(src, () -> {}, e));
3402  
3403 <            fs.add(src.thenComposeAsync((z) -> null, e));
3403 >            fs.add(src.thenComposeAsync(z -> null, e));
3404              fs.add(src.whenCompleteAsync((z, t) -> {}, e));
3405              fs.add(src.handleAsync((z, t) -> null, e));
3406  
# Line 3418 | Line 3433 | public class CompletableFutureTest exten
3433          {
3434              List<CompletableFuture<?>> fs = new ArrayList<>();
3435  
3436 <            fs.add(complete.applyToEitherAsync(incomplete, (z) -> z, e));
3437 <            fs.add(incomplete.applyToEitherAsync(complete, (z) -> z, e));
3436 >            fs.add(complete.applyToEitherAsync(incomplete, z -> z, e));
3437 >            fs.add(incomplete.applyToEitherAsync(complete, z -> z, e));
3438  
3439 <            fs.add(complete.acceptEitherAsync(incomplete, (z) -> {}, e));
3440 <            fs.add(incomplete.acceptEitherAsync(complete, (z) -> {}, e));
3439 >            fs.add(complete.acceptEitherAsync(incomplete, z -> {}, e));
3440 >            fs.add(incomplete.acceptEitherAsync(complete, z -> {}, e));
3441  
3442              fs.add(complete.runAfterEitherAsync(incomplete, () -> {}, e));
3443              fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e));
# Line 3461 | Line 3476 | public class CompletableFutureTest exten
3476  
3477          List<CompletableFuture<?>> fs = new ArrayList<>();
3478          fs.add(incomplete.thenRunAsync(() -> {}, e));
3479 <        fs.add(incomplete.thenAcceptAsync((z) -> {}, e));
3480 <        fs.add(incomplete.thenApplyAsync((z) -> z, e));
3479 >        fs.add(incomplete.thenAcceptAsync(z -> {}, e));
3480 >        fs.add(incomplete.thenApplyAsync(z -> z, e));
3481  
3482          fs.add(incomplete.thenCombineAsync(incomplete, (x, y) -> x, e));
3483          fs.add(incomplete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3484          fs.add(incomplete.runAfterBothAsync(incomplete, () -> {}, e));
3485  
3486 <        fs.add(incomplete.applyToEitherAsync(incomplete, (z) -> z, e));
3487 <        fs.add(incomplete.acceptEitherAsync(incomplete, (z) -> {}, e));
3486 >        fs.add(incomplete.applyToEitherAsync(incomplete, z -> z, e));
3487 >        fs.add(incomplete.acceptEitherAsync(incomplete, z -> {}, e));
3488          fs.add(incomplete.runAfterEitherAsync(incomplete, () -> {}, e));
3489  
3490 <        fs.add(incomplete.thenComposeAsync((z) -> null, e));
3490 >        fs.add(incomplete.thenComposeAsync(z -> null, e));
3491          fs.add(incomplete.whenCompleteAsync((z, t) -> {}, e));
3492          fs.add(incomplete.handleAsync((z, t) -> null, e));
3493  
# Line 3532 | Line 3547 | public class CompletableFutureTest exten
3547       */
3548      public void testCompletedStage() {
3549          AtomicInteger x = new AtomicInteger(0);
3550 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3550 >        AtomicReference<Throwable> r = new AtomicReference<>();
3551          CompletionStage<Integer> f = CompletableFuture.completedStage(1);
3552          f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3553          assertEquals(x.get(), 1);
# Line 3577 | Line 3592 | public class CompletableFutureTest exten
3592       * copy returns a CompletableFuture that is completed normally,
3593       * with the same value, when source is.
3594       */
3595 <    public void testCopy() {
3595 >    public void testCopy_normalCompletion() {
3596 >        for (boolean createIncomplete : new boolean[] { true, false })
3597 >        for (Integer v1 : new Integer[] { 1, null })
3598 >    {
3599          CompletableFuture<Integer> f = new CompletableFuture<>();
3600 +        if (!createIncomplete) assertTrue(f.complete(v1));
3601          CompletableFuture<Integer> g = f.copy();
3602 <        checkIncomplete(f);
3603 <        checkIncomplete(g);
3604 <        f.complete(1);
3605 <        checkCompletedNormally(f, 1);
3606 <        checkCompletedNormally(g, 1);
3607 <    }
3602 >        if (createIncomplete) {
3603 >            checkIncomplete(f);
3604 >            checkIncomplete(g);
3605 >            assertTrue(f.complete(v1));
3606 >        }
3607 >        checkCompletedNormally(f, v1);
3608 >        checkCompletedNormally(g, v1);
3609 >    }}
3610  
3611      /**
3612       * copy returns a CompletableFuture that is completed exceptionally
3613       * when source is.
3614       */
3615 <    public void testCopy2() {
3615 >    public void testCopy_exceptionalCompletion() {
3616 >        for (boolean createIncomplete : new boolean[] { true, false })
3617 >    {
3618 >        CFException ex = new CFException();
3619          CompletableFuture<Integer> f = new CompletableFuture<>();
3620 +        if (!createIncomplete) f.completeExceptionally(ex);
3621          CompletableFuture<Integer> g = f.copy();
3622 <        checkIncomplete(f);
3623 <        checkIncomplete(g);
3624 <        CFException ex = new CFException();
3625 <        f.completeExceptionally(ex);
3622 >        if (createIncomplete) {
3623 >            checkIncomplete(f);
3624 >            checkIncomplete(g);
3625 >            f.completeExceptionally(ex);
3626 >        }
3627          checkCompletedExceptionally(f, ex);
3628          checkCompletedWithWrappedException(g, ex);
3629 +    }}
3630 +
3631 +    /**
3632 +     * Completion of a copy does not complete its source.
3633 +     */
3634 +    public void testCopy_oneWayPropagation() {
3635 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3636 +        assertTrue(f.copy().complete(1));
3637 +        assertTrue(f.copy().complete(null));
3638 +        assertTrue(f.copy().cancel(true));
3639 +        assertTrue(f.copy().cancel(false));
3640 +        assertTrue(f.copy().completeExceptionally(new CFException()));
3641 +        checkIncomplete(f);
3642      }
3643  
3644      /**
# Line 3610 | Line 3649 | public class CompletableFutureTest exten
3649          CompletableFuture<Integer> f = new CompletableFuture<>();
3650          CompletionStage<Integer> g = f.minimalCompletionStage();
3651          AtomicInteger x = new AtomicInteger(0);
3652 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3652 >        AtomicReference<Throwable> r = new AtomicReference<>();
3653          checkIncomplete(f);
3654          g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3655          f.complete(1);
# Line 3627 | Line 3666 | public class CompletableFutureTest exten
3666          CompletableFuture<Integer> f = new CompletableFuture<>();
3667          CompletionStage<Integer> g = f.minimalCompletionStage();
3668          AtomicInteger x = new AtomicInteger(0);
3669 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3669 >        AtomicReference<Throwable> r = new AtomicReference<>();
3670          g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3671          checkIncomplete(f);
3672          CFException ex = new CFException();
# Line 3645 | Line 3684 | public class CompletableFutureTest exten
3684          CFException ex = new CFException();
3685          CompletionStage<Integer> f = CompletableFuture.failedStage(ex);
3686          AtomicInteger x = new AtomicInteger(0);
3687 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3687 >        AtomicReference<Throwable> r = new AtomicReference<>();
3688          f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3689          assertEquals(x.get(), 0);
3690          assertEquals(r.get(), ex);
# Line 3669 | Line 3708 | public class CompletableFutureTest exten
3708      public void testCompleteAsync2() {
3709          CompletableFuture<Integer> f = new CompletableFuture<>();
3710          CFException ex = new CFException();
3711 <        f.completeAsync(() -> {if (true) throw ex; return 1;});
3711 >        f.completeAsync(() -> { throw ex; });
3712          try {
3713              f.join();
3714              shouldThrow();
# Line 3699 | Line 3738 | public class CompletableFutureTest exten
3738          CompletableFuture<Integer> f = new CompletableFuture<>();
3739          CFException ex = new CFException();
3740          ThreadExecutor executor = new ThreadExecutor();
3741 <        f.completeAsync(() -> {if (true) throw ex; return 1;}, executor);
3741 >        f.completeAsync(() -> { throw ex; }, executor);
3742          try {
3743              f.join();
3744              shouldThrow();
# Line 3858 | Line 3897 | public class CompletableFutureTest exten
3897          List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> funs
3898              = new ArrayList<>();
3899  
3900 <        funs.add((y) -> m.thenRun(y, noopRunnable));
3901 <        funs.add((y) -> m.thenAccept(y, noopConsumer));
3902 <        funs.add((y) -> m.thenApply(y, incFunction));
3903 <
3904 <        funs.add((y) -> m.runAfterEither(y, incomplete, noopRunnable));
3905 <        funs.add((y) -> m.acceptEither(y, incomplete, noopConsumer));
3906 <        funs.add((y) -> m.applyToEither(y, incomplete, incFunction));
3907 <
3908 <        funs.add((y) -> m.runAfterBoth(y, v42, noopRunnable));
3909 <        funs.add((y) -> m.runAfterBoth(v42, y, noopRunnable));
3910 <        funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3911 <        funs.add((y) -> m.thenAcceptBoth(v42, y, new SubtractAction(m)));
3912 <        funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
3913 <        funs.add((y) -> m.thenCombine(v42, y, new SubtractFunction(m)));
3914 <
3915 <        funs.add((y) -> m.whenComplete(y, (Integer r, Throwable t) -> {}));
3916 <
3917 <        funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3918 <
3919 <        funs.add((y) -> CompletableFuture.allOf(y));
3920 <        funs.add((y) -> CompletableFuture.allOf(y, v42));
3921 <        funs.add((y) -> CompletableFuture.allOf(v42, y));
3922 <        funs.add((y) -> CompletableFuture.anyOf(y));
3923 <        funs.add((y) -> CompletableFuture.anyOf(y, incomplete));
3924 <        funs.add((y) -> CompletableFuture.anyOf(incomplete, y));
3900 >        funs.add(y -> m.thenRun(y, noopRunnable));
3901 >        funs.add(y -> m.thenAccept(y, noopConsumer));
3902 >        funs.add(y -> m.thenApply(y, incFunction));
3903 >
3904 >        funs.add(y -> m.runAfterEither(y, incomplete, noopRunnable));
3905 >        funs.add(y -> m.acceptEither(y, incomplete, noopConsumer));
3906 >        funs.add(y -> m.applyToEither(y, incomplete, incFunction));
3907 >
3908 >        funs.add(y -> m.runAfterBoth(y, v42, noopRunnable));
3909 >        funs.add(y -> m.runAfterBoth(v42, y, noopRunnable));
3910 >        funs.add(y -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3911 >        funs.add(y -> m.thenAcceptBoth(v42, y, new SubtractAction(m)));
3912 >        funs.add(y -> m.thenCombine(y, v42, new SubtractFunction(m)));
3913 >        funs.add(y -> m.thenCombine(v42, y, new SubtractFunction(m)));
3914 >
3915 >        funs.add(y -> m.whenComplete(y, (Integer r, Throwable t) -> {}));
3916 >
3917 >        funs.add(y -> m.thenCompose(y, new CompletableFutureInc(m)));
3918 >
3919 >        funs.add(y -> CompletableFuture.allOf(y));
3920 >        funs.add(y -> CompletableFuture.allOf(y, v42));
3921 >        funs.add(y -> CompletableFuture.allOf(v42, y));
3922 >        funs.add(y -> CompletableFuture.anyOf(y));
3923 >        funs.add(y -> CompletableFuture.anyOf(y, incomplete));
3924 >        funs.add(y -> CompletableFuture.anyOf(incomplete, y));
3925  
3926          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3927                   fun : funs) {
# Line 3939 | Line 3978 | public class CompletableFutureTest exten
3978      public void testMinimalCompletionStage_minimality() {
3979          if (!testImplementationDetails) return;
3980          Function<Method, String> toSignature =
3981 <            (method) -> method.getName() + Arrays.toString(method.getParameterTypes());
3981 >            method -> method.getName() + Arrays.toString(method.getParameterTypes());
3982          Predicate<Method> isNotStatic =
3983 <            (method) -> (method.getModifiers() & Modifier.STATIC) == 0;
3983 >            method -> (method.getModifiers() & Modifier.STATIC) == 0;
3984          List<Method> minimalMethods =
3985              Stream.of(Object.class, CompletionStage.class)
3986 <            .flatMap((klazz) -> Stream.of(klazz.getMethods()))
3986 >            .flatMap(klazz -> Stream.of(klazz.getMethods()))
3987              .filter(isNotStatic)
3988              .collect(Collectors.toList());
3989          // Methods from CompletableFuture permitted NOT to throw UOE
# Line 3960 | Line 3999 | public class CompletableFutureTest exten
3999              .collect(Collectors.toSet());
4000          List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods())
4001              .filter(isNotStatic)
4002 <            .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method)))
4002 >            .filter(method -> !permittedMethodSignatures.contains(toSignature.apply(method)))
4003              .collect(Collectors.toList());
4004  
4005          List<CompletionStage<Integer>> stages = new ArrayList<>();
4006 <        stages.add(new CompletableFuture<Integer>().minimalCompletionStage());
4006 >        CompletionStage<Integer> min =
4007 >            new CompletableFuture<Integer>().minimalCompletionStage();
4008 >        stages.add(min);
4009 >        stages.add(min.thenApply(x -> x));
4010          stages.add(CompletableFuture.completedStage(1));
4011          stages.add(CompletableFuture.failedStage(new CFException()));
4012  
# Line 4000 | Line 4042 | public class CompletableFutureTest exten
4042              throw new Error("Methods did not throw UOE: " + bugs);
4043      }
4044  
4045 +    /**
4046 +     * minimalStage.toCompletableFuture() returns a CompletableFuture that
4047 +     * is completed normally, with the same value, when source is.
4048 +     */
4049 +    public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() {
4050 +        for (boolean createIncomplete : new boolean[] { true, false })
4051 +        for (Integer v1 : new Integer[] { 1, null })
4052 +    {
4053 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4054 +        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4055 +        if (!createIncomplete) assertTrue(f.complete(v1));
4056 +        CompletableFuture<Integer> g = minimal.toCompletableFuture();
4057 +        if (createIncomplete) {
4058 +            checkIncomplete(f);
4059 +            checkIncomplete(g);
4060 +            assertTrue(f.complete(v1));
4061 +        }
4062 +        checkCompletedNormally(f, v1);
4063 +        checkCompletedNormally(g, v1);
4064 +    }}
4065 +
4066 +    /**
4067 +     * minimalStage.toCompletableFuture() returns a CompletableFuture that
4068 +     * is completed exceptionally when source is.
4069 +     */
4070 +    public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() {
4071 +        for (boolean createIncomplete : new boolean[] { true, false })
4072 +    {
4073 +        CFException ex = new CFException();
4074 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4075 +        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4076 +        if (!createIncomplete) f.completeExceptionally(ex);
4077 +        CompletableFuture<Integer> g = minimal.toCompletableFuture();
4078 +        if (createIncomplete) {
4079 +            checkIncomplete(f);
4080 +            checkIncomplete(g);
4081 +            f.completeExceptionally(ex);
4082 +        }
4083 +        checkCompletedExceptionally(f, ex);
4084 +        checkCompletedWithWrappedException(g, ex);
4085 +    }}
4086 +
4087 +    /**
4088 +     * minimalStage.toCompletableFuture() gives mutable CompletableFuture
4089 +     */
4090 +    public void testMinimalCompletionStage_toCompletableFuture_mutable() {
4091 +        for (Integer v1 : new Integer[] { 1, null })
4092 +    {
4093 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4094 +        CompletionStage minimal = f.minimalCompletionStage();
4095 +        CompletableFuture<Integer> g = minimal.toCompletableFuture();
4096 +        assertTrue(g.complete(v1));
4097 +        checkCompletedNormally(g, v1);
4098 +        checkIncomplete(f);
4099 +        checkIncomplete(minimal.toCompletableFuture());
4100 +    }}
4101 +
4102 +    /**
4103 +     * minimalStage.toCompletableFuture().join() awaits completion
4104 +     */
4105 +    public void testMinimalCompletionStage_toCompletableFuture_join() throws Exception {
4106 +        for (boolean createIncomplete : new boolean[] { true, false })
4107 +        for (Integer v1 : new Integer[] { 1, null })
4108 +    {
4109 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4110 +        if (!createIncomplete) assertTrue(f.complete(v1));
4111 +        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4112 +        if (createIncomplete) assertTrue(f.complete(v1));
4113 +        assertEquals(v1, minimal.toCompletableFuture().join());
4114 +        assertEquals(v1, minimal.toCompletableFuture().get());
4115 +        checkCompletedNormally(minimal.toCompletableFuture(), v1);
4116 +    }}
4117 +
4118 +    /**
4119 +     * Completion of a toCompletableFuture copy of a minimal stage
4120 +     * does not complete its source.
4121 +     */
4122 +    public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() {
4123 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4124 +        CompletionStage<Integer> g = f.minimalCompletionStage();
4125 +        assertTrue(g.toCompletableFuture().complete(1));
4126 +        assertTrue(g.toCompletableFuture().complete(null));
4127 +        assertTrue(g.toCompletableFuture().cancel(true));
4128 +        assertTrue(g.toCompletableFuture().cancel(false));
4129 +        assertTrue(g.toCompletableFuture().completeExceptionally(new CFException()));
4130 +        checkIncomplete(g.toCompletableFuture());
4131 +        f.complete(1);
4132 +        checkCompletedNormally(g.toCompletableFuture(), 1);
4133 +    }
4134 +
4135 +    /** Demo utility method for external reliable toCompletableFuture */
4136 +    static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) {
4137 +        CompletableFuture<T> f = new CompletableFuture<>();
4138 +        stage.handle((T t, Throwable ex) -> {
4139 +                         if (ex != null) f.completeExceptionally(ex);
4140 +                         else f.complete(t);
4141 +                         return null;
4142 +                     });
4143 +        return f;
4144 +    }
4145 +
4146 +    /** Demo utility method to join a CompletionStage */
4147 +    static <T> T join(CompletionStage<T> stage) {
4148 +        return toCompletableFuture(stage).join();
4149 +    }
4150 +
4151 +    /**
4152 +     * Joining a minimal stage "by hand" works
4153 +     */
4154 +    public void testMinimalCompletionStage_join_by_hand() {
4155 +        for (boolean createIncomplete : new boolean[] { true, false })
4156 +        for (Integer v1 : new Integer[] { 1, null })
4157 +    {
4158 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4159 +        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4160 +        CompletableFuture<Integer> g = new CompletableFuture<>();
4161 +        if (!createIncomplete) assertTrue(f.complete(v1));
4162 +        minimal.thenAccept(x -> g.complete(x));
4163 +        if (createIncomplete) assertTrue(f.complete(v1));
4164 +        g.join();
4165 +        checkCompletedNormally(g, v1);
4166 +        checkCompletedNormally(f, v1);
4167 +        assertEquals(v1, join(minimal));
4168 +    }}
4169 +
4170      static class Monad {
4171          static class ZeroException extends RuntimeException {
4172              public ZeroException() { super("monadic zero"); }
# Line 4016 | Line 4183 | public class CompletableFutureTest exten
4183          static <T,U,V> Function<T, CompletableFuture<V>> compose
4184              (Function<T, CompletableFuture<U>> f,
4185               Function<U, CompletableFuture<V>> g) {
4186 <            return (x) -> f.apply(x).thenCompose(g);
4186 >            return x -> f.apply(x).thenCompose(g);
4187          }
4188  
4189          static void assertZero(CompletableFuture<?> f) {
4190              try {
4191                  f.getNow(null);
4192 <                throw new AssertionFailedError("should throw");
4192 >                throw new AssertionError("should throw");
4193              } catch (CompletionException success) {
4194                  assertTrue(success.getCause() instanceof ZeroException);
4195              }
# Line 4096 | Line 4263 | public class CompletableFutureTest exten
4263  
4264          // Some mutually non-commutative functions
4265          Function<Long, CompletableFuture<Long>> triple
4266 <            = (x) -> Monad.unit(3 * x);
4266 >            = x -> Monad.unit(3 * x);
4267          Function<Long, CompletableFuture<Long>> inc
4268 <            = (x) -> Monad.unit(x + 1);
4268 >            = x -> Monad.unit(x + 1);
4269  
4270          // unit is a right identity: m >>= unit === m
4271          Monad.assertFutureEquals(inc.apply(5L).thenCompose(unit),
# Line 4110 | Line 4277 | public class CompletableFutureTest exten
4277          // associativity: (m >>= f) >>= g === m >>= ( \x -> (f x >>= g) )
4278          Monad.assertFutureEquals(
4279              unit.apply(5L).thenCompose(inc).thenCompose(triple),
4280 <            unit.apply(5L).thenCompose((x) -> inc.apply(x).thenCompose(triple)));
4280 >            unit.apply(5L).thenCompose(x -> inc.apply(x).thenCompose(triple)));
4281  
4282          // The case for CompletableFuture as an additive monad is weaker...
4283  
# Line 4120 | Line 4287 | public class CompletableFutureTest exten
4287          // left zero: zero >>= f === zero
4288          Monad.assertZero(zero.thenCompose(inc));
4289          // right zero: f >>= (\x -> zero) === zero
4290 <        Monad.assertZero(inc.apply(5L).thenCompose((x) -> zero));
4290 >        Monad.assertZero(inc.apply(5L).thenCompose(x -> zero));
4291  
4292          // f plus zero === f
4293          Monad.assertFutureEquals(Monad.unit(5L),
# Line 4147 | Line 4314 | public class CompletableFutureTest exten
4314      }
4315  
4316      /** Test long recursive chains of CompletableFutures with cascading completions */
4317 +    @SuppressWarnings("FutureReturnValueIgnored")
4318      public void testRecursiveChains() throws Throwable {
4319          for (ExecutionMode m : ExecutionMode.values())
4320          for (boolean addDeadEnds : new boolean[] { true, false })
# Line 4171 | Line 4339 | public class CompletableFutureTest exten
4339       * A single CompletableFuture with many dependents.
4340       * A demo of scalability - runtime is O(n).
4341       */
4342 +    @SuppressWarnings("FutureReturnValueIgnored")
4343      public void testManyDependents() throws Throwable {
4344          final int n = expensiveTests ? 1_000_000 : 10;
4345          final CompletableFuture<Void> head = new CompletableFuture<>();
# Line 4178 | Line 4347 | public class CompletableFutureTest exten
4347          final AtomicInteger count = new AtomicInteger(0);
4348          for (int i = 0; i < n; i++) {
4349              head.thenRun(() -> count.getAndIncrement());
4350 <            head.thenAccept((x) -> count.getAndIncrement());
4351 <            head.thenApply((x) -> count.getAndIncrement());
4350 >            head.thenAccept(x -> count.getAndIncrement());
4351 >            head.thenApply(x -> count.getAndIncrement());
4352  
4353              head.runAfterBoth(complete, () -> count.getAndIncrement());
4354              head.thenAcceptBoth(complete, (x, y) -> count.getAndIncrement());
# Line 4189 | Line 4358 | public class CompletableFutureTest exten
4358              complete.thenCombine(head, (x, y) -> count.getAndIncrement());
4359  
4360              head.runAfterEither(new CompletableFuture<Void>(), () -> count.getAndIncrement());
4361 <            head.acceptEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement());
4362 <            head.applyToEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement());
4361 >            head.acceptEither(new CompletableFuture<Void>(), x -> count.getAndIncrement());
4362 >            head.applyToEither(new CompletableFuture<Void>(), x -> count.getAndIncrement());
4363              new CompletableFuture<Void>().runAfterEither(head, () -> count.getAndIncrement());
4364 <            new CompletableFuture<Void>().acceptEither(head, (x) -> count.getAndIncrement());
4365 <            new CompletableFuture<Void>().applyToEither(head, (x) -> count.getAndIncrement());
4364 >            new CompletableFuture<Void>().acceptEither(head, x -> count.getAndIncrement());
4365 >            new CompletableFuture<Void>().applyToEither(head, x -> count.getAndIncrement());
4366          }
4367          head.complete(null);
4368          assertEquals(5 * 3 * n, count.get());
4369      }
4370  
4371      /** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */
4372 +    @SuppressWarnings("FutureReturnValueIgnored")
4373      public void testCoCompletionGarbageRetention() throws Throwable {
4374          final int n = expensiveTests ? 1_000_000 : 10;
4375          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
# Line 4210 | Line 4380 | public class CompletableFutureTest exten
4380              f.complete(null);
4381  
4382              f = new CompletableFuture<>();
4383 <            f.acceptEither(incomplete, (x) -> {});
4383 >            f.acceptEither(incomplete, x -> {});
4384              f.complete(null);
4385  
4386              f = new CompletableFuture<>();
4387 <            f.applyToEither(incomplete, (x) -> x);
4387 >            f.applyToEither(incomplete, x -> x);
4388              f.complete(null);
4389  
4390              f = new CompletableFuture<>();
# Line 4228 | Line 4398 | public class CompletableFutureTest exten
4398              f.complete(null);
4399  
4400              f = new CompletableFuture<>();
4401 <            incomplete.acceptEither(f, (x) -> {});
4401 >            incomplete.acceptEither(f, x -> {});
4402              f.complete(null);
4403  
4404              f = new CompletableFuture<>();
4405 <            incomplete.applyToEither(f, (x) -> x);
4405 >            incomplete.applyToEither(f, x -> x);
4406              f.complete(null);
4407  
4408              f = new CompletableFuture<>();
# Line 4290 | Line 4460 | public class CompletableFutureTest exten
4460              assertTrue(neverCompleted.thenRun(() -> {}).cancel(true));
4461      }
4462  
4463 +    /**
4464 +     * Checks for garbage retention when MinimalStage.toCompletableFuture()
4465 +     * is invoked many times.
4466 +     * 8161600: Garbage retention when source CompletableFutures are never completed
4467 +     *
4468 +     * As of 2016-07, fails with OOME:
4469 +     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testToCompletableFutureGarbageRetention tck
4470 +     */
4471 +    public void testToCompletableFutureGarbageRetention() throws Throwable {
4472 +        final int n = expensiveTests ? 900_000 : 10;
4473 +        CompletableFuture<Integer> neverCompleted = new CompletableFuture<>();
4474 +        CompletionStage minimal = neverCompleted.minimalCompletionStage();
4475 +        for (int i = 0; i < n; i++)
4476 +            assertTrue(minimal.toCompletableFuture().cancel(true));
4477 +    }
4478 +
4479   //     static <U> U join(CompletionStage<U> stage) {
4480   //         CompletableFuture<U> f = new CompletableFuture<>();
4481   //         stage.whenComplete((v, ex) -> {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines