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.120 by jsr166, Sun Sep 6 16:47:24 2015 UTC vs.
Revision 1.154 by jsr166, Sun Jun 26 19:27:42 2016 UTC

# Line 7 | Line 7
7  
8   import static java.util.concurrent.TimeUnit.MILLISECONDS;
9   import static java.util.concurrent.TimeUnit.SECONDS;
10 + import static java.util.concurrent.CompletableFuture.completedFuture;
11 + import static java.util.concurrent.CompletableFuture.failedFuture;
12 +
13 + import java.lang.reflect.Method;
14 + import java.lang.reflect.Modifier;
15 +
16 + import java.util.stream.Collectors;
17 + import java.util.stream.Stream;
18  
19   import java.util.ArrayList;
20 + import java.util.Arrays;
21   import java.util.List;
22   import java.util.Objects;
23 + import java.util.Set;
24   import java.util.concurrent.Callable;
25   import java.util.concurrent.CancellationException;
26   import java.util.concurrent.CompletableFuture;
# Line 20 | Line 30 | import java.util.concurrent.ExecutionExc
30   import java.util.concurrent.Executor;
31   import java.util.concurrent.ForkJoinPool;
32   import java.util.concurrent.ForkJoinTask;
33 + import java.util.concurrent.RejectedExecutionException;
34   import java.util.concurrent.TimeoutException;
35   import java.util.concurrent.TimeUnit;
36   import java.util.concurrent.atomic.AtomicInteger;
# Line 28 | Line 39 | import java.util.function.BiConsumer;
39   import java.util.function.BiFunction;
40   import java.util.function.Consumer;
41   import java.util.function.Function;
42 + import java.util.function.Predicate;
43   import java.util.function.Supplier;
44  
45 + import junit.framework.AssertionFailedError;
46   import junit.framework.Test;
47   import junit.framework.TestSuite;
48  
# Line 77 | Line 90 | public class CompletableFutureTest exten
90          assertTrue(f.toString().contains("[Completed normally]"));
91      }
92  
93 <    void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
94 <        long startTime = System.nanoTime();
95 <        long timeoutMillis = LONG_DELAY_MS;
96 <        try {
97 <            f.get(timeoutMillis, MILLISECONDS);
98 <            shouldThrow();
99 <        } catch (ExecutionException success) {
100 <            assertTrue(success.getCause() instanceof CFException);
101 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
102 <        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
103 <
104 <        try {
105 <            f.join();
106 <            shouldThrow();
107 <        } catch (CompletionException success) {
108 <            assertTrue(success.getCause() instanceof CFException);
109 <        }
97 <        try {
98 <            f.getNow(null);
99 <            shouldThrow();
100 <        } catch (CompletionException success) {
101 <            assertTrue(success.getCause() instanceof CFException);
93 >    /**
94 >     * Returns the "raw" internal exceptional completion of f,
95 >     * without any additional wrapping with CompletionException.
96 >     */
97 >    <U> Throwable exceptionalCompletion(CompletableFuture<U> f) {
98 >        // handle (and whenComplete) can distinguish between "direct"
99 >        // and "wrapped" exceptional completion
100 >        return f.handle((U u, Throwable t) -> t).join();
101 >    }
102 >
103 >    void checkCompletedExceptionally(CompletableFuture<?> f,
104 >                                     boolean wrapped,
105 >                                     Consumer<Throwable> checker) {
106 >        Throwable cause = exceptionalCompletion(f);
107 >        if (wrapped) {
108 >            assertTrue(cause instanceof CompletionException);
109 >            cause = cause.getCause();
110          }
111 <        try {
104 <            f.get();
105 <            shouldThrow();
106 <        } catch (ExecutionException success) {
107 <            assertTrue(success.getCause() instanceof CFException);
108 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
109 <        assertTrue(f.isDone());
110 <        assertFalse(f.isCancelled());
111 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
112 <    }
111 >        checker.accept(cause);
112  
114    <U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f,
115                                                      Throwable ex) {
113          long startTime = System.nanoTime();
117        long timeoutMillis = LONG_DELAY_MS;
114          try {
115 <            f.get(timeoutMillis, MILLISECONDS);
115 >            f.get(LONG_DELAY_MS, MILLISECONDS);
116              shouldThrow();
117          } catch (ExecutionException success) {
118 <            assertSame(ex, success.getCause());
118 >            assertSame(cause, success.getCause());
119          } catch (Throwable fail) { threadUnexpectedException(fail); }
120 <        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
120 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS / 2);
121  
122          try {
123              f.join();
124              shouldThrow();
125          } catch (CompletionException success) {
126 <            assertSame(ex, success.getCause());
127 <        }
126 >            assertSame(cause, success.getCause());
127 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
128 >
129          try {
130              f.getNow(null);
131              shouldThrow();
132          } catch (CompletionException success) {
133 <            assertSame(ex, success.getCause());
134 <        }
133 >            assertSame(cause, success.getCause());
134 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
135 >
136          try {
137              f.get();
138              shouldThrow();
139          } catch (ExecutionException success) {
140 <            assertSame(ex, success.getCause());
140 >            assertSame(cause, success.getCause());
141          } catch (Throwable fail) { threadUnexpectedException(fail); }
142  
145        assertTrue(f.isDone());
143          assertFalse(f.isCancelled());
144 +        assertTrue(f.isDone());
145 +        assertTrue(f.isCompletedExceptionally());
146          assertTrue(f.toString().contains("[Completed exceptionally]"));
147      }
148  
149 <    <U> void checkCompletedExceptionallyWithTimeout(CompletableFuture<U> f) {
150 <        long startTime = System.nanoTime();
151 <        long timeoutMillis = LONG_DELAY_MS;
152 <        try {
154 <            f.get(timeoutMillis, MILLISECONDS);
155 <            shouldThrow();
156 <        } catch (ExecutionException ex) {
157 <            assertTrue(ex.getCause() instanceof TimeoutException);
158 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
159 <        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
160 <
161 <        try {
162 <            f.join();
163 <            shouldThrow();
164 <        } catch (Throwable ex) {
165 <            assertTrue(ex.getCause() instanceof TimeoutException);
166 <        }
167 <
168 <        try {
169 <            f.getNow(null);
170 <            shouldThrow();
171 <        } catch (Throwable ex) {
172 <            assertTrue(ex.getCause() instanceof TimeoutException);
173 <        }
149 >    void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
150 >        checkCompletedExceptionally(f, true,
151 >            (t) -> assertTrue(t instanceof CFException));
152 >    }
153  
154 <        try {
155 <            f.get();
156 <            shouldThrow();
157 <        } catch (ExecutionException ex) {
179 <            assertTrue(ex.getCause() instanceof TimeoutException);
180 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
154 >    void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
155 >        checkCompletedExceptionally(f, true,
156 >            (t) -> assertTrue(t instanceof CancellationException));
157 >    }
158  
159 <        assertTrue(f.isDone());
160 <        assertFalse(f.isCancelled());
161 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
159 >    void checkCompletedWithTimeoutException(CompletableFuture<?> f) {
160 >        checkCompletedExceptionally(f, false,
161 >            (t) -> assertTrue(t instanceof TimeoutException));
162      }
163  
164 <    <U> void checkCompletedWithWrappedException(CompletableFuture<U> f,
165 <                                                Throwable ex) {
166 <        checkCompletedExceptionallyWithRootCause(f, ex);
190 <        try {
191 <            CompletableFuture<Throwable> spy = f.handle
192 <                ((U u, Throwable t) -> t);
193 <            assertTrue(spy.join() instanceof CompletionException);
194 <            assertSame(ex, spy.join().getCause());
195 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
164 >    void checkCompletedWithWrappedException(CompletableFuture<?> f,
165 >                                            Throwable ex) {
166 >        checkCompletedExceptionally(f, true, (t) -> assertSame(t, ex));
167      }
168  
169 <    <U> void checkCompletedExceptionally(CompletableFuture<U> f, Throwable ex) {
170 <        checkCompletedExceptionallyWithRootCause(f, ex);
200 <        try {
201 <            CompletableFuture<Throwable> spy = f.handle
202 <                ((U u, Throwable t) -> t);
203 <            assertSame(ex, spy.join());
204 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
169 >    void checkCompletedExceptionally(CompletableFuture<?> f, Throwable ex) {
170 >        checkCompletedExceptionally(f, false, (t) -> assertSame(t, ex));
171      }
172  
173      void checkCancelled(CompletableFuture<?> f) {
174          long startTime = System.nanoTime();
209        long timeoutMillis = LONG_DELAY_MS;
175          try {
176 <            f.get(timeoutMillis, MILLISECONDS);
176 >            f.get(LONG_DELAY_MS, MILLISECONDS);
177              shouldThrow();
178          } catch (CancellationException success) {
179          } catch (Throwable fail) { threadUnexpectedException(fail); }
180 <        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
180 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS / 2);
181  
182          try {
183              f.join();
# Line 227 | Line 192 | public class CompletableFutureTest exten
192              shouldThrow();
193          } catch (CancellationException success) {
194          } catch (Throwable fail) { threadUnexpectedException(fail); }
230        assertTrue(f.isDone());
231        assertTrue(f.isCompletedExceptionally());
232        assertTrue(f.isCancelled());
233        assertTrue(f.toString().contains("[Completed exceptionally]"));
234    }
195  
196 <    void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
237 <        long startTime = System.nanoTime();
238 <        long timeoutMillis = LONG_DELAY_MS;
239 <        try {
240 <            f.get(timeoutMillis, MILLISECONDS);
241 <            shouldThrow();
242 <        } catch (ExecutionException success) {
243 <            assertTrue(success.getCause() instanceof CancellationException);
244 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
245 <        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
196 >        assertTrue(exceptionalCompletion(f) instanceof CancellationException);
197  
247        try {
248            f.join();
249            shouldThrow();
250        } catch (CompletionException success) {
251            assertTrue(success.getCause() instanceof CancellationException);
252        }
253        try {
254            f.getNow(null);
255            shouldThrow();
256        } catch (CompletionException success) {
257            assertTrue(success.getCause() instanceof CancellationException);
258        }
259        try {
260            f.get();
261            shouldThrow();
262        } catch (ExecutionException success) {
263            assertTrue(success.getCause() instanceof CancellationException);
264        } catch (Throwable fail) { threadUnexpectedException(fail); }
198          assertTrue(f.isDone());
266        assertFalse(f.isCancelled());
199          assertTrue(f.isCompletedExceptionally());
200 +        assertTrue(f.isCancelled());
201          assertTrue(f.toString().contains("[Completed exceptionally]"));
202      }
203  
# Line 527 | Line 460 | public class CompletableFutureTest exten
460      class FailingSupplier extends CheckedAction
461          implements Supplier<Integer>
462      {
463 <        FailingSupplier(ExecutionMode m) { super(m); }
463 >        final CFException ex;
464 >        FailingSupplier(ExecutionMode m) { super(m); ex = new CFException(); }
465          public Integer get() {
466              invoked();
467 <            throw new CFException();
467 >            throw ex;
468          }
469      }
470  
471      class FailingConsumer extends CheckedIntegerAction
472          implements Consumer<Integer>
473      {
474 <        FailingConsumer(ExecutionMode m) { super(m); }
474 >        final CFException ex;
475 >        FailingConsumer(ExecutionMode m) { super(m); ex = new CFException(); }
476          public void accept(Integer x) {
477              invoked();
478              value = x;
479 <            throw new CFException();
479 >            throw ex;
480          }
481      }
482  
483      class FailingBiConsumer extends CheckedIntegerAction
484          implements BiConsumer<Integer, Integer>
485      {
486 <        FailingBiConsumer(ExecutionMode m) { super(m); }
486 >        final CFException ex;
487 >        FailingBiConsumer(ExecutionMode m) { super(m); ex = new CFException(); }
488          public void accept(Integer x, Integer y) {
489              invoked();
490              value = subtract(x, y);
491 <            throw new CFException();
491 >            throw ex;
492          }
493      }
494  
495      class FailingFunction extends CheckedIntegerAction
496          implements Function<Integer, Integer>
497      {
498 <        FailingFunction(ExecutionMode m) { super(m); }
498 >        final CFException ex;
499 >        FailingFunction(ExecutionMode m) { super(m); ex = new CFException(); }
500          public Integer apply(Integer x) {
501              invoked();
502              value = x;
503 <            throw new CFException();
503 >            throw ex;
504          }
505      }
506  
507      class FailingBiFunction extends CheckedIntegerAction
508          implements BiFunction<Integer, Integer, Integer>
509      {
510 <        FailingBiFunction(ExecutionMode m) { super(m); }
510 >        final CFException ex;
511 >        FailingBiFunction(ExecutionMode m) { super(m); ex = new CFException(); }
512          public Integer apply(Integer x, Integer y) {
513              invoked();
514              value = subtract(x, y);
515 <            throw new CFException();
515 >            throw ex;
516          }
517      }
518  
519      class FailingRunnable extends CheckedAction implements Runnable {
520 <        FailingRunnable(ExecutionMode m) { super(m); }
520 >        final CFException ex;
521 >        FailingRunnable(ExecutionMode m) { super(m); ex = new CFException(); }
522          public void run() {
523              invoked();
524 <            throw new CFException();
524 >            throw ex;
525          }
526      }
527  
# Line 602 | Line 541 | public class CompletableFutureTest exten
541      class FailingCompletableFutureFunction extends CheckedIntegerAction
542          implements Function<Integer, CompletableFuture<Integer>>
543      {
544 <        FailingCompletableFutureFunction(ExecutionMode m) { super(m); }
544 >        final CFException ex;
545 >        FailingCompletableFutureFunction(ExecutionMode m) { super(m); ex = new CFException(); }
546          public CompletableFuture<Integer> apply(Integer x) {
547              invoked();
548              value = x;
549 <            throw new CFException();
549 >            throw ex;
550          }
551      }
552  
# Line 908 | Line 848 | public class CompletableFutureTest exten
848          if (!createIncomplete) assertTrue(f.complete(v1));
849          final CompletableFuture<Integer> g = f.exceptionally
850              ((Throwable t) -> {
911                // Should not be called
851                  a.getAndIncrement();
852 <                throw new AssertionError();
852 >                threadFail("should not be called");
853 >                return null;            // unreached
854              });
855          if (createIncomplete) assertTrue(f.complete(v1));
856  
# Line 944 | Line 884 | public class CompletableFutureTest exten
884          assertEquals(1, a.get());
885      }}
886  
887 +    /**
888 +     * If an "exceptionally action" throws an exception, it completes
889 +     * exceptionally with that exception
890 +     */
891      public void testExceptionally_exceptionalCompletionActionFailed() {
892          for (boolean createIncomplete : new boolean[] { true, false })
893      {
# Line 962 | Line 906 | public class CompletableFutureTest exten
906          if (createIncomplete) f.completeExceptionally(ex1);
907  
908          checkCompletedWithWrappedException(g, ex2);
909 +        checkCompletedExceptionally(f, ex1);
910          assertEquals(1, a.get());
911      }}
912  
# Line 969 | Line 914 | public class CompletableFutureTest exten
914       * whenComplete action executes on normal completion, propagating
915       * source result.
916       */
917 <    public void testWhenComplete_normalCompletion1() {
917 >    public void testWhenComplete_normalCompletion() {
918          for (ExecutionMode m : ExecutionMode.values())
919          for (boolean createIncomplete : new boolean[] { true, false })
920          for (Integer v1 : new Integer[] { 1, null })
# Line 979 | Line 924 | public class CompletableFutureTest exten
924          if (!createIncomplete) assertTrue(f.complete(v1));
925          final CompletableFuture<Integer> g = m.whenComplete
926              (f,
927 <             (Integer x, Throwable t) -> {
927 >             (Integer result, Throwable t) -> {
928                  m.checkExecutionMode();
929 <                threadAssertSame(x, v1);
929 >                threadAssertSame(result, v1);
930                  threadAssertNull(t);
931                  a.getAndIncrement();
932              });
# Line 1006 | Line 951 | public class CompletableFutureTest exten
951          if (!createIncomplete) f.completeExceptionally(ex);
952          final CompletableFuture<Integer> g = m.whenComplete
953              (f,
954 <             (Integer x, Throwable t) -> {
954 >             (Integer result, Throwable t) -> {
955                  m.checkExecutionMode();
956 <                threadAssertNull(x);
956 >                threadAssertNull(result);
957                  threadAssertSame(t, ex);
958                  a.getAndIncrement();
959              });
# Line 1033 | Line 978 | public class CompletableFutureTest exten
978          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
979          final CompletableFuture<Integer> g = m.whenComplete
980              (f,
981 <             (Integer x, Throwable t) -> {
981 >             (Integer result, Throwable t) -> {
982                  m.checkExecutionMode();
983 <                threadAssertNull(x);
983 >                threadAssertNull(result);
984                  threadAssertTrue(t instanceof CancellationException);
985                  a.getAndIncrement();
986              });
# Line 1050 | Line 995 | public class CompletableFutureTest exten
995       * If a whenComplete action throws an exception when triggered by
996       * a normal completion, it completes exceptionally
997       */
998 <    public void testWhenComplete_actionFailed() {
998 >    public void testWhenComplete_sourceCompletedNormallyActionFailed() {
999          for (boolean createIncomplete : new boolean[] { true, false })
1000          for (ExecutionMode m : ExecutionMode.values())
1001          for (Integer v1 : new Integer[] { 1, null })
# Line 1061 | Line 1006 | public class CompletableFutureTest exten
1006          if (!createIncomplete) assertTrue(f.complete(v1));
1007          final CompletableFuture<Integer> g = m.whenComplete
1008              (f,
1009 <             (Integer x, Throwable t) -> {
1009 >             (Integer result, Throwable t) -> {
1010                  m.checkExecutionMode();
1011 <                threadAssertSame(x, v1);
1011 >                threadAssertSame(result, v1);
1012                  threadAssertNull(t);
1013                  a.getAndIncrement();
1014                  throw ex;
# Line 1078 | Line 1023 | public class CompletableFutureTest exten
1023      /**
1024       * If a whenComplete action throws an exception when triggered by
1025       * a source completion that also throws an exception, the source
1026 <     * exception takes precedence.
1026 >     * exception takes precedence (unlike handle)
1027       */
1028 <    public void testWhenComplete_actionFailedSourceFailed() {
1028 >    public void testWhenComplete_sourceFailedActionFailed() {
1029          for (boolean createIncomplete : new boolean[] { true, false })
1030          for (ExecutionMode m : ExecutionMode.values())
1031      {
# Line 1092 | Line 1037 | public class CompletableFutureTest exten
1037          if (!createIncomplete) f.completeExceptionally(ex1);
1038          final CompletableFuture<Integer> g = m.whenComplete
1039              (f,
1040 <             (Integer x, Throwable t) -> {
1040 >             (Integer result, Throwable t) -> {
1041                  m.checkExecutionMode();
1042                  threadAssertSame(t, ex1);
1043 <                threadAssertNull(x);
1043 >                threadAssertNull(result);
1044                  a.getAndIncrement();
1045                  throw ex2;
1046              });
# Line 1103 | Line 1048 | public class CompletableFutureTest exten
1048  
1049          checkCompletedWithWrappedException(g, ex1);
1050          checkCompletedExceptionally(f, ex1);
1051 +        if (testImplementationDetails) {
1052 +            assertEquals(1, ex1.getSuppressed().length);
1053 +            assertSame(ex2, ex1.getSuppressed()[0]);
1054 +        }
1055          assertEquals(1, a.get());
1056      }}
1057  
# Line 1120 | Line 1069 | public class CompletableFutureTest exten
1069          if (!createIncomplete) assertTrue(f.complete(v1));
1070          final CompletableFuture<Integer> g = m.handle
1071              (f,
1072 <             (Integer x, Throwable t) -> {
1072 >             (Integer result, Throwable t) -> {
1073                  m.checkExecutionMode();
1074 <                threadAssertSame(x, v1);
1074 >                threadAssertSame(result, v1);
1075                  threadAssertNull(t);
1076                  a.getAndIncrement();
1077                  return inc(v1);
# Line 1149 | Line 1098 | public class CompletableFutureTest exten
1098          if (!createIncomplete) f.completeExceptionally(ex);
1099          final CompletableFuture<Integer> g = m.handle
1100              (f,
1101 <             (Integer x, Throwable t) -> {
1101 >             (Integer result, Throwable t) -> {
1102                  m.checkExecutionMode();
1103 <                threadAssertNull(x);
1103 >                threadAssertNull(result);
1104                  threadAssertSame(t, ex);
1105                  a.getAndIncrement();
1106                  return v1;
# Line 1178 | Line 1127 | public class CompletableFutureTest exten
1127          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1128          final CompletableFuture<Integer> g = m.handle
1129              (f,
1130 <             (Integer x, Throwable t) -> {
1130 >             (Integer result, Throwable t) -> {
1131                  m.checkExecutionMode();
1132 <                threadAssertNull(x);
1132 >                threadAssertNull(result);
1133                  threadAssertTrue(t instanceof CancellationException);
1134                  a.getAndIncrement();
1135                  return v1;
# Line 1193 | Line 1142 | public class CompletableFutureTest exten
1142      }}
1143  
1144      /**
1145 <     * handle result completes exceptionally if action does
1145 >     * If a "handle action" throws an exception when triggered by
1146 >     * a normal completion, it completes exceptionally
1147       */
1148 <    public void testHandle_sourceFailedActionFailed() {
1148 >    public void testHandle_sourceCompletedNormallyActionFailed() {
1149          for (ExecutionMode m : ExecutionMode.values())
1150          for (boolean createIncomplete : new boolean[] { true, false })
1151 +        for (Integer v1 : new Integer[] { 1, null })
1152      {
1153          final CompletableFuture<Integer> f = new CompletableFuture<>();
1154          final AtomicInteger a = new AtomicInteger(0);
1155 <        final CFException ex1 = new CFException();
1156 <        final CFException ex2 = new CFException();
1206 <        if (!createIncomplete) f.completeExceptionally(ex1);
1155 >        final CFException ex = new CFException();
1156 >        if (!createIncomplete) assertTrue(f.complete(v1));
1157          final CompletableFuture<Integer> g = m.handle
1158              (f,
1159 <             (Integer x, Throwable t) -> {
1159 >             (Integer result, Throwable t) -> {
1160                  m.checkExecutionMode();
1161 <                threadAssertNull(x);
1162 <                threadAssertSame(ex1, t);
1161 >                threadAssertSame(result, v1);
1162 >                threadAssertNull(t);
1163                  a.getAndIncrement();
1164 <                throw ex2;
1164 >                throw ex;
1165              });
1166 <        if (createIncomplete) f.completeExceptionally(ex1);
1166 >        if (createIncomplete) assertTrue(f.complete(v1));
1167  
1168 <        checkCompletedWithWrappedException(g, ex2);
1169 <        checkCompletedExceptionally(f, ex1);
1168 >        checkCompletedWithWrappedException(g, ex);
1169 >        checkCompletedNormally(f, v1);
1170          assertEquals(1, a.get());
1171      }}
1172  
1173 <    public void testHandle_sourceCompletedNormallyActionFailed() {
1174 <        for (ExecutionMode m : ExecutionMode.values())
1173 >    /**
1174 >     * If a "handle action" throws an exception when triggered by
1175 >     * a source completion that also throws an exception, the action
1176 >     * exception takes precedence (unlike whenComplete)
1177 >     */
1178 >    public void testHandle_sourceFailedActionFailed() {
1179          for (boolean createIncomplete : new boolean[] { true, false })
1180 <        for (Integer v1 : new Integer[] { 1, null })
1180 >        for (ExecutionMode m : ExecutionMode.values())
1181      {
1228        final CompletableFuture<Integer> f = new CompletableFuture<>();
1182          final AtomicInteger a = new AtomicInteger(0);
1183 <        final CFException ex = new CFException();
1184 <        if (!createIncomplete) assertTrue(f.complete(v1));
1183 >        final CFException ex1 = new CFException();
1184 >        final CFException ex2 = new CFException();
1185 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1186 >
1187 >        if (!createIncomplete) f.completeExceptionally(ex1);
1188          final CompletableFuture<Integer> g = m.handle
1189              (f,
1190 <             (Integer x, Throwable t) -> {
1190 >             (Integer result, Throwable t) -> {
1191                  m.checkExecutionMode();
1192 <                threadAssertSame(x, v1);
1193 <                threadAssertNull(t);
1192 >                threadAssertNull(result);
1193 >                threadAssertSame(ex1, t);
1194                  a.getAndIncrement();
1195 <                throw ex;
1195 >                throw ex2;
1196              });
1197 <        if (createIncomplete) assertTrue(f.complete(v1));
1197 >        if (createIncomplete) f.completeExceptionally(ex1);
1198  
1199 <        checkCompletedWithWrappedException(g, ex);
1200 <        checkCompletedNormally(f, v1);
1199 >        checkCompletedWithWrappedException(g, ex2);
1200 >        checkCompletedExceptionally(f, ex1);
1201          assertEquals(1, a.get());
1202      }}
1203  
# Line 1274 | Line 1230 | public class CompletableFutureTest exten
1230      {
1231          final FailingRunnable r = new FailingRunnable(m);
1232          final CompletableFuture<Void> f = m.runAsync(r);
1233 <        checkCompletedWithWrappedCFException(f);
1233 >        checkCompletedWithWrappedException(f, r.ex);
1234          r.assertInvoked();
1235      }}
1236  
# Line 1308 | Line 1264 | public class CompletableFutureTest exten
1264      {
1265          FailingSupplier r = new FailingSupplier(m);
1266          CompletableFuture<Integer> f = m.supplyAsync(r);
1267 <        checkCompletedWithWrappedCFException(f);
1267 >        checkCompletedWithWrappedException(f, r.ex);
1268          r.assertInvoked();
1269      }}
1270  
# Line 1430 | Line 1386 | public class CompletableFutureTest exten
1386          final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]);
1387          final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]);
1388  
1389 <        checkCompletedWithWrappedCFException(h0);
1390 <        checkCompletedWithWrappedCFException(h1);
1391 <        checkCompletedWithWrappedCFException(h2);
1392 <        checkCompletedWithWrappedCFException(h3);
1393 <        checkCompletedWithWrappedCFException(h4);
1394 <        checkCompletedWithWrappedCFException(h5);
1389 >        checkCompletedWithWrappedException(h0, rs[0].ex);
1390 >        checkCompletedWithWrappedException(h1, rs[1].ex);
1391 >        checkCompletedWithWrappedException(h2, rs[2].ex);
1392 >        checkCompletedWithWrappedException(h3, rs[3].ex);
1393 >        checkCompletedWithWrappedException(h4, rs[4].ex);
1394 >        checkCompletedWithWrappedException(h5, rs[5].ex);
1395          checkCompletedNormally(f, v1);
1396      }}
1397  
# Line 1534 | Line 1490 | public class CompletableFutureTest exten
1490          final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]);
1491          final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]);
1492  
1493 <        checkCompletedWithWrappedCFException(h0);
1494 <        checkCompletedWithWrappedCFException(h1);
1495 <        checkCompletedWithWrappedCFException(h2);
1496 <        checkCompletedWithWrappedCFException(h3);
1493 >        checkCompletedWithWrappedException(h0, rs[0].ex);
1494 >        checkCompletedWithWrappedException(h1, rs[1].ex);
1495 >        checkCompletedWithWrappedException(h2, rs[2].ex);
1496 >        checkCompletedWithWrappedException(h3, rs[3].ex);
1497          checkCompletedNormally(f, v1);
1498      }}
1499  
# Line 1636 | Line 1592 | public class CompletableFutureTest exten
1592          final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1593          final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1594  
1595 <        checkCompletedWithWrappedCFException(h0);
1596 <        checkCompletedWithWrappedCFException(h1);
1597 <        checkCompletedWithWrappedCFException(h2);
1598 <        checkCompletedWithWrappedCFException(h3);
1595 >        checkCompletedWithWrappedException(h0, rs[0].ex);
1596 >        checkCompletedWithWrappedException(h1, rs[1].ex);
1597 >        checkCompletedWithWrappedException(h2, rs[2].ex);
1598 >        checkCompletedWithWrappedException(h3, rs[3].ex);
1599          checkCompletedNormally(f, v1);
1600      }}
1601  
# Line 1801 | Line 1757 | public class CompletableFutureTest exten
1757          assertTrue(snd.complete(w2));
1758          final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1759  
1760 <        checkCompletedWithWrappedCFException(h1);
1761 <        checkCompletedWithWrappedCFException(h2);
1762 <        checkCompletedWithWrappedCFException(h3);
1760 >        checkCompletedWithWrappedException(h1, r1.ex);
1761 >        checkCompletedWithWrappedException(h2, r2.ex);
1762 >        checkCompletedWithWrappedException(h3, r3.ex);
1763          r1.assertInvoked();
1764          r2.assertInvoked();
1765          r3.assertInvoked();
# Line 1965 | Line 1921 | public class CompletableFutureTest exten
1921          assertTrue(snd.complete(w2));
1922          final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1923  
1924 <        checkCompletedWithWrappedCFException(h1);
1925 <        checkCompletedWithWrappedCFException(h2);
1926 <        checkCompletedWithWrappedCFException(h3);
1924 >        checkCompletedWithWrappedException(h1, r1.ex);
1925 >        checkCompletedWithWrappedException(h2, r2.ex);
1926 >        checkCompletedWithWrappedException(h3, r3.ex);
1927          r1.assertInvoked();
1928          r2.assertInvoked();
1929          r3.assertInvoked();
# Line 2129 | Line 2085 | public class CompletableFutureTest exten
2085          assertTrue(snd.complete(w2));
2086          final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3);
2087  
2088 <        checkCompletedWithWrappedCFException(h1);
2089 <        checkCompletedWithWrappedCFException(h2);
2090 <        checkCompletedWithWrappedCFException(h3);
2088 >        checkCompletedWithWrappedException(h1, r1.ex);
2089 >        checkCompletedWithWrappedException(h2, r2.ex);
2090 >        checkCompletedWithWrappedException(h3, r3.ex);
2091          r1.assertInvoked();
2092          r2.assertInvoked();
2093          r3.assertInvoked();
# Line 2421 | Line 2377 | public class CompletableFutureTest exten
2377          f.complete(v1);
2378          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
2379          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
2380 <        checkCompletedWithWrappedCFException(h0);
2381 <        checkCompletedWithWrappedCFException(h1);
2382 <        checkCompletedWithWrappedCFException(h2);
2383 <        checkCompletedWithWrappedCFException(h3);
2380 >        checkCompletedWithWrappedException(h0, rs[0].ex);
2381 >        checkCompletedWithWrappedException(h1, rs[1].ex);
2382 >        checkCompletedWithWrappedException(h2, rs[2].ex);
2383 >        checkCompletedWithWrappedException(h3, rs[3].ex);
2384          for (int i = 0; i < 4; i++) rs[i].assertValue(v1);
2385  
2386          g.complete(v2);
# Line 2433 | Line 2389 | public class CompletableFutureTest exten
2389          final CompletableFuture<Integer> h4 = m.applyToEither(f, g, rs[4]);
2390          final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]);
2391  
2392 <        checkCompletedWithWrappedCFException(h4);
2392 >        checkCompletedWithWrappedException(h4, rs[4].ex);
2393          assertTrue(Objects.equals(v1, rs[4].value) ||
2394                     Objects.equals(v2, rs[4].value));
2395 <        checkCompletedWithWrappedCFException(h5);
2395 >        checkCompletedWithWrappedException(h5, rs[5].ex);
2396          assertTrue(Objects.equals(v1, rs[5].value) ||
2397                     Objects.equals(v2, rs[5].value));
2398  
# Line 2680 | Line 2636 | public class CompletableFutureTest exten
2636          f.complete(v1);
2637          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2638          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2639 <        checkCompletedWithWrappedCFException(h0);
2640 <        checkCompletedWithWrappedCFException(h1);
2641 <        checkCompletedWithWrappedCFException(h2);
2642 <        checkCompletedWithWrappedCFException(h3);
2639 >        checkCompletedWithWrappedException(h0, rs[0].ex);
2640 >        checkCompletedWithWrappedException(h1, rs[1].ex);
2641 >        checkCompletedWithWrappedException(h2, rs[2].ex);
2642 >        checkCompletedWithWrappedException(h3, rs[3].ex);
2643          for (int i = 0; i < 4; i++) rs[i].assertValue(v1);
2644  
2645          g.complete(v2);
# Line 2692 | Line 2648 | public class CompletableFutureTest exten
2648          final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]);
2649          final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]);
2650  
2651 <        checkCompletedWithWrappedCFException(h4);
2651 >        checkCompletedWithWrappedException(h4, rs[4].ex);
2652          assertTrue(Objects.equals(v1, rs[4].value) ||
2653                     Objects.equals(v2, rs[4].value));
2654 <        checkCompletedWithWrappedCFException(h5);
2654 >        checkCompletedWithWrappedException(h5, rs[5].ex);
2655          assertTrue(Objects.equals(v1, rs[5].value) ||
2656                     Objects.equals(v2, rs[5].value));
2657  
# Line 2935 | Line 2891 | public class CompletableFutureTest exten
2891          assertTrue(f.complete(v1));
2892          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2893          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2894 <        checkCompletedWithWrappedCFException(h0);
2895 <        checkCompletedWithWrappedCFException(h1);
2896 <        checkCompletedWithWrappedCFException(h2);
2897 <        checkCompletedWithWrappedCFException(h3);
2894 >        checkCompletedWithWrappedException(h0, rs[0].ex);
2895 >        checkCompletedWithWrappedException(h1, rs[1].ex);
2896 >        checkCompletedWithWrappedException(h2, rs[2].ex);
2897 >        checkCompletedWithWrappedException(h3, rs[3].ex);
2898          for (int i = 0; i < 4; i++) rs[i].assertInvoked();
2899          assertTrue(g.complete(v2));
2900          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2901          final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2902 <        checkCompletedWithWrappedCFException(h4);
2903 <        checkCompletedWithWrappedCFException(h5);
2902 >        checkCompletedWithWrappedException(h4, rs[4].ex);
2903 >        checkCompletedWithWrappedException(h5, rs[5].ex);
2904  
2905          checkCompletedNormally(f, v1);
2906          checkCompletedNormally(g, v2);
# Line 3005 | Line 2961 | public class CompletableFutureTest exten
2961          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2962          if (createIncomplete) assertTrue(f.complete(v1));
2963  
2964 <        checkCompletedWithWrappedCFException(g);
2964 >        checkCompletedWithWrappedException(g, r.ex);
2965          checkCompletedNormally(f, v1);
2966      }}
2967  
# Line 3114 | Line 3070 | public class CompletableFutureTest exten
3070          }
3071      }
3072  
3073 <    public void testAllOf_backwards() throws Exception {
3073 >    public void testAllOf_normal_backwards() throws Exception {
3074          for (int k = 1; k < 10; k++) {
3075              CompletableFuture<Integer>[] fs
3076                  = (CompletableFuture<Integer>[]) new CompletableFuture[k];
# Line 3142 | Line 3098 | public class CompletableFutureTest exten
3098              for (int i = 0; i < k; i++) {
3099                  checkIncomplete(f);
3100                  checkIncomplete(CompletableFuture.allOf(fs));
3101 <                if (i != k/2) {
3101 >                if (i != k / 2) {
3102                      fs[i].complete(i);
3103                      checkCompletedNormally(fs[i], i);
3104                  } else {
# Line 3347 | Line 3303 | public class CompletableFutureTest exten
3303              () -> f.obtrudeException(null),
3304  
3305              () -> CompletableFuture.delayedExecutor(1L, SECONDS, null),
3306 <            () -> CompletableFuture.delayedExecutor(1L, null, new ThreadExecutor()),
3306 >            () -> CompletableFuture.delayedExecutor(1L, null, exec),
3307              () -> CompletableFuture.delayedExecutor(1L, null),
3308  
3309              () -> f.orTimeout(1L, null),
3310              () -> f.completeOnTimeout(42, 1L, null),
3311 +
3312 +            () -> CompletableFuture.failedFuture(null),
3313 +            () -> CompletableFuture.failedStage(null),
3314          };
3315  
3316          assertThrows(NullPointerException.class, throwingActions);
3317          assertEquals(0, exec.count.get());
3318      }
3319  
3320 +    static class CountingRejectingExecutor implements Executor {
3321 +        final RejectedExecutionException ex = new RejectedExecutionException();
3322 +        final AtomicInteger count = new AtomicInteger(0);
3323 +        public void execute(Runnable r) {
3324 +            count.getAndIncrement();
3325 +            throw ex;
3326 +        }
3327 +    }
3328 +
3329 +    /**
3330 +     * Test submissions to an executor that rejects all tasks.
3331 +     */
3332 +    public void testRejectingExecutor() {
3333 +        for (Integer v : new Integer[] { 1, null }) {
3334 +
3335 +        final CountingRejectingExecutor e = new CountingRejectingExecutor();
3336 +
3337 +        final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3338 +        final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3339 +
3340 +        List<CompletableFuture<?>> futures = new ArrayList<>();
3341 +
3342 +        List<CompletableFuture<Integer>> srcs = new ArrayList<>();
3343 +        srcs.add(complete);
3344 +        srcs.add(incomplete);
3345 +
3346 +        for (CompletableFuture<Integer> src : srcs) {
3347 +            List<CompletableFuture<?>> fs = new ArrayList<>();
3348 +            fs.add(src.thenRunAsync(() -> {}, e));
3349 +            fs.add(src.thenAcceptAsync((z) -> {}, e));
3350 +            fs.add(src.thenApplyAsync((z) -> z, e));
3351 +
3352 +            fs.add(src.thenCombineAsync(src, (x, y) -> x, e));
3353 +            fs.add(src.thenAcceptBothAsync(src, (x, y) -> {}, e));
3354 +            fs.add(src.runAfterBothAsync(src, () -> {}, e));
3355 +
3356 +            fs.add(src.applyToEitherAsync(src, (z) -> z, e));
3357 +            fs.add(src.acceptEitherAsync(src, (z) -> {}, e));
3358 +            fs.add(src.runAfterEitherAsync(src, () -> {}, e));
3359 +
3360 +            fs.add(src.thenComposeAsync((z) -> null, e));
3361 +            fs.add(src.whenCompleteAsync((z, t) -> {}, e));
3362 +            fs.add(src.handleAsync((z, t) -> null, e));
3363 +
3364 +            for (CompletableFuture<?> future : fs) {
3365 +                if (src.isDone())
3366 +                    checkCompletedWithWrappedException(future, e.ex);
3367 +                else
3368 +                    checkIncomplete(future);
3369 +            }
3370 +            futures.addAll(fs);
3371 +        }
3372 +
3373 +        {
3374 +            List<CompletableFuture<?>> fs = new ArrayList<>();
3375 +
3376 +            fs.add(complete.thenCombineAsync(incomplete, (x, y) -> x, e));
3377 +            fs.add(incomplete.thenCombineAsync(complete, (x, y) -> x, e));
3378 +
3379 +            fs.add(complete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3380 +            fs.add(incomplete.thenAcceptBothAsync(complete, (x, y) -> {}, e));
3381 +
3382 +            fs.add(complete.runAfterBothAsync(incomplete, () -> {}, e));
3383 +            fs.add(incomplete.runAfterBothAsync(complete, () -> {}, e));
3384 +
3385 +            for (CompletableFuture<?> future : fs)
3386 +                checkIncomplete(future);
3387 +            futures.addAll(fs);
3388 +        }
3389 +
3390 +        {
3391 +            List<CompletableFuture<?>> fs = new ArrayList<>();
3392 +
3393 +            fs.add(complete.applyToEitherAsync(incomplete, (z) -> z, e));
3394 +            fs.add(incomplete.applyToEitherAsync(complete, (z) -> z, e));
3395 +
3396 +            fs.add(complete.acceptEitherAsync(incomplete, (z) -> {}, e));
3397 +            fs.add(incomplete.acceptEitherAsync(complete, (z) -> {}, e));
3398 +
3399 +            fs.add(complete.runAfterEitherAsync(incomplete, () -> {}, e));
3400 +            fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e));
3401 +
3402 +            for (CompletableFuture<?> future : fs)
3403 +                checkCompletedWithWrappedException(future, e.ex);
3404 +            futures.addAll(fs);
3405 +        }
3406 +
3407 +        incomplete.complete(v);
3408 +
3409 +        for (CompletableFuture<?> future : futures)
3410 +            checkCompletedWithWrappedException(future, e.ex);
3411 +
3412 +        assertEquals(futures.size(), e.count.get());
3413 +
3414 +        }
3415 +    }
3416 +
3417 +    /**
3418 +     * Test submissions to an executor that rejects all tasks, but
3419 +     * should never be invoked because the dependent future is
3420 +     * explicitly completed.
3421 +     */
3422 +    public void testRejectingExecutorNeverInvoked() {
3423 +        final CountingRejectingExecutor e = new CountingRejectingExecutor();
3424 +
3425 +        for (Integer v : new Integer[] { 1, null }) {
3426 +
3427 +        final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3428 +        final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3429 +
3430 +        List<CompletableFuture<?>> futures = new ArrayList<>();
3431 +
3432 +        List<CompletableFuture<Integer>> srcs = new ArrayList<>();
3433 +        srcs.add(complete);
3434 +        srcs.add(incomplete);
3435 +
3436 +        List<CompletableFuture<?>> fs = new ArrayList<>();
3437 +        fs.add(incomplete.thenRunAsync(() -> {}, e));
3438 +        fs.add(incomplete.thenAcceptAsync((z) -> {}, e));
3439 +        fs.add(incomplete.thenApplyAsync((z) -> z, e));
3440 +
3441 +        fs.add(incomplete.thenCombineAsync(incomplete, (x, y) -> x, e));
3442 +        fs.add(incomplete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3443 +        fs.add(incomplete.runAfterBothAsync(incomplete, () -> {}, e));
3444 +
3445 +        fs.add(incomplete.applyToEitherAsync(incomplete, (z) -> z, e));
3446 +        fs.add(incomplete.acceptEitherAsync(incomplete, (z) -> {}, e));
3447 +        fs.add(incomplete.runAfterEitherAsync(incomplete, () -> {}, e));
3448 +
3449 +        fs.add(incomplete.thenComposeAsync((z) -> null, e));
3450 +        fs.add(incomplete.whenCompleteAsync((z, t) -> {}, e));
3451 +        fs.add(incomplete.handleAsync((z, t) -> null, e));
3452 +
3453 +        fs.add(complete.thenCombineAsync(incomplete, (x, y) -> x, e));
3454 +        fs.add(incomplete.thenCombineAsync(complete, (x, y) -> x, e));
3455 +
3456 +        fs.add(complete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3457 +        fs.add(incomplete.thenAcceptBothAsync(complete, (x, y) -> {}, e));
3458 +
3459 +        fs.add(complete.runAfterBothAsync(incomplete, () -> {}, e));
3460 +        fs.add(incomplete.runAfterBothAsync(complete, () -> {}, e));
3461 +
3462 +        for (CompletableFuture<?> future : fs)
3463 +            checkIncomplete(future);
3464 +
3465 +        for (CompletableFuture<?> future : fs)
3466 +            future.complete(null);
3467 +
3468 +        incomplete.complete(v);
3469 +
3470 +        for (CompletableFuture<?> future : fs)
3471 +            checkCompletedNormally(future, null);
3472 +
3473 +        assertEquals(0, e.count.get());
3474 +
3475 +        }
3476 +    }
3477 +
3478      /**
3479       * toCompletableFuture returns this CompletableFuture.
3480       */
# Line 3458 | Line 3575 | public class CompletableFutureTest exten
3575          CFException ex = new CFException();
3576          f.completeExceptionally(ex);
3577          checkCompletedExceptionally(f, ex);
3578 <        checkCompletedWithWrappedCFException(g);
3578 >        checkCompletedWithWrappedException(g, ex);
3579      }
3580  
3581      /**
# Line 3514 | Line 3631 | public class CompletableFutureTest exten
3631       * completeAsync completes with value of given supplier
3632       */
3633      public void testCompleteAsync() {
3634 +        for (Integer v1 : new Integer[] { 1, null })
3635 +    {
3636          CompletableFuture<Integer> f = new CompletableFuture<>();
3637 <        f.completeAsync(() -> 1);
3637 >        f.completeAsync(() -> v1);
3638          f.join();
3639 <        checkCompletedNormally(f, 1);
3640 <    }
3639 >        checkCompletedNormally(f, v1);
3640 >    }}
3641  
3642      /**
3643       * completeAsync completes exceptionally if given supplier throws
# Line 3530 | Line 3649 | public class CompletableFutureTest exten
3649          try {
3650              f.join();
3651              shouldThrow();
3652 <        } catch (Exception success) {}
3653 <        checkCompletedWithWrappedCFException(f);
3652 >        } catch (CompletionException success) {}
3653 >        checkCompletedWithWrappedException(f, ex);
3654      }
3655  
3656      /**
3657       * completeAsync with given executor completes with value of given supplier
3658       */
3659      public void testCompleteAsync3() {
3660 +        for (Integer v1 : new Integer[] { 1, null })
3661 +    {
3662          CompletableFuture<Integer> f = new CompletableFuture<>();
3663 <        f.completeAsync(() -> 1, new ThreadExecutor());
3664 <        f.join();
3665 <        checkCompletedNormally(f, 1);
3666 <    }
3663 >        ThreadExecutor executor = new ThreadExecutor();
3664 >        f.completeAsync(() -> v1, executor);
3665 >        assertSame(v1, f.join());
3666 >        checkCompletedNormally(f, v1);
3667 >        assertEquals(1, executor.count.get());
3668 >    }}
3669  
3670      /**
3671       * completeAsync with given executor completes exceptionally if
# Line 3551 | Line 3674 | public class CompletableFutureTest exten
3674      public void testCompleteAsync4() {
3675          CompletableFuture<Integer> f = new CompletableFuture<>();
3676          CFException ex = new CFException();
3677 <        f.completeAsync(() -> {if (true) throw ex; return 1;}, new ThreadExecutor());
3677 >        ThreadExecutor executor = new ThreadExecutor();
3678 >        f.completeAsync(() -> {if (true) throw ex; return 1;}, executor);
3679          try {
3680              f.join();
3681              shouldThrow();
3682 <        } catch (Exception success) {}
3683 <        checkCompletedWithWrappedCFException(f);
3682 >        } catch (CompletionException success) {}
3683 >        checkCompletedWithWrappedException(f, ex);
3684 >        assertEquals(1, executor.count.get());
3685      }
3686  
3687      /**
3688       * orTimeout completes with TimeoutException if not complete
3689       */
3690 <    public void testOrTimeout() {
3690 >    public void testOrTimeout_timesOut() {
3691 >        long timeoutMillis = timeoutMillis();
3692          CompletableFuture<Integer> f = new CompletableFuture<>();
3693 <        f.orTimeout(SHORT_DELAY_MS, MILLISECONDS);
3694 <        checkCompletedExceptionallyWithTimeout(f);
3693 >        long startTime = System.nanoTime();
3694 >        assertSame(f, f.orTimeout(timeoutMillis, MILLISECONDS));
3695 >        checkCompletedWithTimeoutException(f);
3696 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
3697      }
3698  
3699      /**
3700       * orTimeout completes normally if completed before timeout
3701       */
3702 <    public void testOrTimeout2() {
3702 >    public void testOrTimeout_completed() {
3703 >        for (Integer v1 : new Integer[] { 1, null })
3704 >    {
3705          CompletableFuture<Integer> f = new CompletableFuture<>();
3706 <        f.complete(1);
3707 <        f.orTimeout(SHORT_DELAY_MS, MILLISECONDS);
3708 <        checkCompletedNormally(f, 1);
3709 <    }
3706 >        CompletableFuture<Integer> g = new CompletableFuture<>();
3707 >        long startTime = System.nanoTime();
3708 >        f.complete(v1);
3709 >        assertSame(f, f.orTimeout(LONG_DELAY_MS, MILLISECONDS));
3710 >        assertSame(g, g.orTimeout(LONG_DELAY_MS, MILLISECONDS));
3711 >        g.complete(v1);
3712 >        checkCompletedNormally(f, v1);
3713 >        checkCompletedNormally(g, v1);
3714 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS / 2);
3715 >    }}
3716  
3717      /**
3718       * completeOnTimeout completes with given value if not complete
3719       */
3720 <    public void testCompleteOnTimeout() {
3721 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3722 <        f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS);
3587 <        f.join();
3588 <        checkCompletedNormally(f, -1);
3720 >    public void testCompleteOnTimeout_timesOut() {
3721 >        testInParallel(() -> testCompleteOnTimeout_timesOut(42),
3722 >                       () -> testCompleteOnTimeout_timesOut(null));
3723      }
3724  
3725      /**
3726 <     * completeOnTimeout has no effect if completed within timeout
3726 >     * completeOnTimeout completes with given value if not complete
3727       */
3728 <    public void testCompleteOnTimeout2() {
3728 >    public void testCompleteOnTimeout_timesOut(Integer v) {
3729 >        long timeoutMillis = timeoutMillis();
3730          CompletableFuture<Integer> f = new CompletableFuture<>();
3731 <        f.complete(1);
3732 <        f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS);
3733 <        checkCompletedNormally(f, 1);
3731 >        long startTime = System.nanoTime();
3732 >        assertSame(f, f.completeOnTimeout(v, timeoutMillis, MILLISECONDS));
3733 >        assertSame(v, f.join());
3734 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
3735 >        f.complete(99);         // should have no effect
3736 >        checkCompletedNormally(f, v);
3737      }
3738  
3739      /**
3740 <     * delayedExecutor returns an executor that delays submission
3740 >     * completeOnTimeout has no effect if completed within timeout
3741       */
3742 <    public void testDelayedExecutor() throws Exception {
3743 <        long timeoutMillis = SMALL_DELAY_MS;
3744 <        Executor d = CompletableFuture.delayedExecutor(timeoutMillis,
3745 <                                                       MILLISECONDS);
3742 >    public void testCompleteOnTimeout_completed() {
3743 >        for (Integer v1 : new Integer[] { 1, null })
3744 >    {
3745 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3746 >        CompletableFuture<Integer> g = new CompletableFuture<>();
3747          long startTime = System.nanoTime();
3748 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d);
3749 <        assertNull(f.getNow(null));
3750 <        assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS));
3751 <        assertTrue(millisElapsedSince(startTime) > timeoutMillis/2);
3752 <        checkCompletedNormally(f, 1);
3753 <    }
3748 >        f.complete(v1);
3749 >        assertSame(f, f.completeOnTimeout(-1, LONG_DELAY_MS, MILLISECONDS));
3750 >        assertSame(g, g.completeOnTimeout(-1, LONG_DELAY_MS, MILLISECONDS));
3751 >        g.complete(v1);
3752 >        checkCompletedNormally(f, v1);
3753 >        checkCompletedNormally(g, v1);
3754 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS / 2);
3755 >    }}
3756  
3757      /**
3758 <     * delayedExecutor for a given executor returns an executor that
3618 <     * delays submission
3758 >     * delayedExecutor returns an executor that delays submission
3759       */
3760 <    public void testDelayedExecutor2() throws Exception {
3761 <        long timeoutMillis = SMALL_DELAY_MS;
3762 <        Executor d = CompletableFuture.delayedExecutor(timeoutMillis,
3763 <                                                       MILLISECONDS,
3764 <                                                       new ThreadExecutor());
3760 >    public void testDelayedExecutor() {
3761 >        testInParallel(() -> testDelayedExecutor(null, null),
3762 >                       () -> testDelayedExecutor(null, 1),
3763 >                       () -> testDelayedExecutor(new ThreadExecutor(), 1),
3764 >                       () -> testDelayedExecutor(new ThreadExecutor(), 1));
3765 >    }
3766 >
3767 >    public void testDelayedExecutor(Executor executor, Integer v) throws Exception {
3768 >        long timeoutMillis = timeoutMillis();
3769 >        // Use an "unreasonably long" long timeout to catch lingering threads
3770 >        long longTimeoutMillis = 1000 * 60 * 60 * 24;
3771 >        final Executor delayer, longDelayer;
3772 >        if (executor == null) {
3773 >            delayer = CompletableFuture.delayedExecutor(timeoutMillis, MILLISECONDS);
3774 >            longDelayer = CompletableFuture.delayedExecutor(longTimeoutMillis, MILLISECONDS);
3775 >        } else {
3776 >            delayer = CompletableFuture.delayedExecutor(timeoutMillis, MILLISECONDS, executor);
3777 >            longDelayer = CompletableFuture.delayedExecutor(longTimeoutMillis, MILLISECONDS, executor);
3778 >        }
3779          long startTime = System.nanoTime();
3780 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d);
3781 <        assertNull(f.getNow(null));
3782 <        assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS));
3783 <        assertTrue(millisElapsedSince(startTime) > timeoutMillis/2);
3784 <        checkCompletedNormally(f, 1);
3780 >        CompletableFuture<Integer> f =
3781 >            CompletableFuture.supplyAsync(() -> v, delayer);
3782 >        CompletableFuture<Integer> g =
3783 >            CompletableFuture.supplyAsync(() -> v, longDelayer);
3784 >
3785 >        assertNull(g.getNow(null));
3786 >
3787 >        assertSame(v, f.get(LONG_DELAY_MS, MILLISECONDS));
3788 >        long millisElapsed = millisElapsedSince(startTime);
3789 >        assertTrue(millisElapsed >= timeoutMillis);
3790 >        assertTrue(millisElapsed < LONG_DELAY_MS / 2);
3791 >
3792 >        checkCompletedNormally(f, v);
3793 >
3794 >        checkIncomplete(g);
3795 >        assertTrue(g.cancel(true));
3796      }
3797  
3798      //--- tests of implementation details; not part of official tck ---
3799  
3800      Object resultOf(CompletableFuture<?> f) {
3801 +        SecurityManager sm = System.getSecurityManager();
3802 +        if (sm != null) {
3803 +            try {
3804 +                System.setSecurityManager(null);
3805 +            } catch (SecurityException giveUp) {
3806 +                return "Reflection not available";
3807 +            }
3808 +        }
3809 +
3810          try {
3811              java.lang.reflect.Field resultField
3812                  = CompletableFuture.class.getDeclaredField("result");
3813              resultField.setAccessible(true);
3814              return resultField.get(f);
3815 <        } catch (Throwable t) { throw new AssertionError(t); }
3815 >        } catch (Throwable t) {
3816 >            throw new AssertionError(t);
3817 >        } finally {
3818 >            if (sm != null) System.setSecurityManager(sm);
3819 >        }
3820      }
3821  
3822      public void testExceptionPropagationReusesResultObject() {
# Line 3661 | Line 3839 | public class CompletableFutureTest exten
3839          funs.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3840  
3841          funs.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3842 +        funs.add((y) -> m.runAfterBoth(v42, y, new Noop(m)));
3843          funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3844 +        funs.add((y) -> m.thenAcceptBoth(v42, y, new SubtractAction(m)));
3845          funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
3846 +        funs.add((y) -> m.thenCombine(v42, y, new SubtractFunction(m)));
3847  
3848 <        funs.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {}));
3848 >        funs.add((y) -> m.whenComplete(y, (Integer r, Throwable t) -> {}));
3849  
3850          funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3851  
3852 +        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y}));
3853          funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42}));
3854 +        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {v42, y}));
3855 +        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y}));
3856          funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete}));
3857 +        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {incomplete, y}));
3858  
3859          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3860                   fun : funs) {
# Line 3720 | Line 3905 | public class CompletableFutureTest exten
3905          }
3906      }}
3907  
3908 +    /**
3909 +     * Minimal completion stages throw UOE for all non-CompletionStage methods
3910 +     */
3911 +    public void testMinimalCompletionStage_minimality() {
3912 +        if (!testImplementationDetails) return;
3913 +        Function<Method, String> toSignature =
3914 +            (method) -> method.getName() + Arrays.toString(method.getParameterTypes());
3915 +        Predicate<Method> isNotStatic =
3916 +            (method) -> (method.getModifiers() & Modifier.STATIC) == 0;
3917 +        List<Method> minimalMethods =
3918 +            Stream.of(Object.class, CompletionStage.class)
3919 +            .flatMap((klazz) -> Stream.of(klazz.getMethods()))
3920 +            .filter(isNotStatic)
3921 +            .collect(Collectors.toList());
3922 +        // Methods from CompletableFuture permitted NOT to throw UOE
3923 +        String[] signatureWhitelist = {
3924 +            "newIncompleteFuture[]",
3925 +            "defaultExecutor[]",
3926 +            "minimalCompletionStage[]",
3927 +            "copy[]",
3928 +        };
3929 +        Set<String> permittedMethodSignatures =
3930 +            Stream.concat(minimalMethods.stream().map(toSignature),
3931 +                          Stream.of(signatureWhitelist))
3932 +            .collect(Collectors.toSet());
3933 +        List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods())
3934 +            .filter(isNotStatic)
3935 +            .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method)))
3936 +            .collect(Collectors.toList());
3937 +
3938 +        CompletionStage<Integer> minimalStage =
3939 +            new CompletableFuture<Integer>().minimalCompletionStage();
3940 +
3941 +        List<Method> bugs = new ArrayList<>();
3942 +        for (Method method : allMethods) {
3943 +            Class<?>[] parameterTypes = method.getParameterTypes();
3944 +            Object[] args = new Object[parameterTypes.length];
3945 +            // Manufacture boxed primitives for primitive params
3946 +            for (int i = 0; i < args.length; i++) {
3947 +                Class<?> type = parameterTypes[i];
3948 +                if (parameterTypes[i] == boolean.class)
3949 +                    args[i] = false;
3950 +                else if (parameterTypes[i] == int.class)
3951 +                    args[i] = 0;
3952 +                else if (parameterTypes[i] == long.class)
3953 +                    args[i] = 0L;
3954 +            }
3955 +            try {
3956 +                method.invoke(minimalStage, args);
3957 +                bugs.add(method);
3958 +            }
3959 +            catch (java.lang.reflect.InvocationTargetException expected) {
3960 +                if (! (expected.getCause() instanceof UnsupportedOperationException)) {
3961 +                    bugs.add(method);
3962 +                    // expected.getCause().printStackTrace();
3963 +                }
3964 +            }
3965 +            catch (ReflectiveOperationException bad) { throw new Error(bad); }
3966 +        }
3967 +        if (!bugs.isEmpty())
3968 +            throw new Error("Methods did not throw UOE: " + bugs.toString());
3969 +    }
3970 +
3971 +    static class Monad {
3972 +        static class ZeroException extends RuntimeException {
3973 +            public ZeroException() { super("monadic zero"); }
3974 +        }
3975 +        // "return", "unit"
3976 +        static <T> CompletableFuture<T> unit(T value) {
3977 +            return completedFuture(value);
3978 +        }
3979 +        // monadic zero ?
3980 +        static <T> CompletableFuture<T> zero() {
3981 +            return failedFuture(new ZeroException());
3982 +        }
3983 +        // >=>
3984 +        static <T,U,V> Function<T, CompletableFuture<V>> compose
3985 +            (Function<T, CompletableFuture<U>> f,
3986 +             Function<U, CompletableFuture<V>> g) {
3987 +            return (x) -> f.apply(x).thenCompose(g);
3988 +        }
3989 +
3990 +        static void assertZero(CompletableFuture<?> f) {
3991 +            try {
3992 +                f.getNow(null);
3993 +                throw new AssertionFailedError("should throw");
3994 +            } catch (CompletionException success) {
3995 +                assertTrue(success.getCause() instanceof ZeroException);
3996 +            }
3997 +        }
3998 +
3999 +        static <T> void assertFutureEquals(CompletableFuture<T> f,
4000 +                                           CompletableFuture<T> g) {
4001 +            T fval = null, gval = null;
4002 +            Throwable fex = null, gex = null;
4003 +
4004 +            try { fval = f.get(); }
4005 +            catch (ExecutionException ex) { fex = ex.getCause(); }
4006 +            catch (Throwable ex) { fex = ex; }
4007 +
4008 +            try { gval = g.get(); }
4009 +            catch (ExecutionException ex) { gex = ex.getCause(); }
4010 +            catch (Throwable ex) { gex = ex; }
4011 +
4012 +            if (fex != null || gex != null)
4013 +                assertSame(fex.getClass(), gex.getClass());
4014 +            else
4015 +                assertEquals(fval, gval);
4016 +        }
4017 +
4018 +        static class PlusFuture<T> extends CompletableFuture<T> {
4019 +            AtomicReference<Throwable> firstFailure = new AtomicReference<>(null);
4020 +        }
4021 +
4022 +        /** Implements "monadic plus". */
4023 +        static <T> CompletableFuture<T> plus(CompletableFuture<? extends T> f,
4024 +                                             CompletableFuture<? extends T> g) {
4025 +            PlusFuture<T> plus = new PlusFuture<T>();
4026 +            BiConsumer<T, Throwable> action = (T result, Throwable ex) -> {
4027 +                try {
4028 +                    if (ex == null) {
4029 +                        if (plus.complete(result))
4030 +                            if (plus.firstFailure.get() != null)
4031 +                                plus.firstFailure.set(null);
4032 +                    }
4033 +                    else if (plus.firstFailure.compareAndSet(null, ex)) {
4034 +                        if (plus.isDone())
4035 +                            plus.firstFailure.set(null);
4036 +                    }
4037 +                    else {
4038 +                        // first failure has precedence
4039 +                        Throwable first = plus.firstFailure.getAndSet(null);
4040 +
4041 +                        // may fail with "Self-suppression not permitted"
4042 +                        try { first.addSuppressed(ex); }
4043 +                        catch (Exception ignored) {}
4044 +
4045 +                        plus.completeExceptionally(first);
4046 +                    }
4047 +                } catch (Throwable unexpected) {
4048 +                    plus.completeExceptionally(unexpected);
4049 +                }
4050 +            };
4051 +            f.whenComplete(action);
4052 +            g.whenComplete(action);
4053 +            return plus;
4054 +        }
4055 +    }
4056 +
4057 +    /**
4058 +     * CompletableFuture is an additive monad - sort of.
4059 +     * https://en.wikipedia.org/wiki/Monad_(functional_programming)#Additive_monads
4060 +     */
4061 +    public void testAdditiveMonad() throws Throwable {
4062 +        Function<Long, CompletableFuture<Long>> unit = Monad::unit;
4063 +        CompletableFuture<Long> zero = Monad.zero();
4064 +
4065 +        // Some mutually non-commutative functions
4066 +        Function<Long, CompletableFuture<Long>> triple
4067 +            = (x) -> Monad.unit(3 * x);
4068 +        Function<Long, CompletableFuture<Long>> inc
4069 +            = (x) -> Monad.unit(x + 1);
4070 +
4071 +        // unit is a right identity: m >>= unit === m
4072 +        Monad.assertFutureEquals(inc.apply(5L).thenCompose(unit),
4073 +                                 inc.apply(5L));
4074 +        // unit is a left identity: (unit x) >>= f === f x
4075 +        Monad.assertFutureEquals(unit.apply(5L).thenCompose(inc),
4076 +                                 inc.apply(5L));
4077 +
4078 +        // associativity: (m >>= f) >>= g === m >>= ( \x -> (f x >>= g) )
4079 +        Monad.assertFutureEquals(
4080 +            unit.apply(5L).thenCompose(inc).thenCompose(triple),
4081 +            unit.apply(5L).thenCompose((x) -> inc.apply(x).thenCompose(triple)));
4082 +
4083 +        // The case for CompletableFuture as an additive monad is weaker...
4084 +
4085 +        // zero is a monadic zero
4086 +        Monad.assertZero(zero);
4087 +
4088 +        // left zero: zero >>= f === zero
4089 +        Monad.assertZero(zero.thenCompose(inc));
4090 +        // right zero: f >>= (\x -> zero) === zero
4091 +        Monad.assertZero(inc.apply(5L).thenCompose((x) -> zero));
4092 +
4093 +        // f plus zero === f
4094 +        Monad.assertFutureEquals(Monad.unit(5L),
4095 +                                 Monad.plus(Monad.unit(5L), zero));
4096 +        // zero plus f === f
4097 +        Monad.assertFutureEquals(Monad.unit(5L),
4098 +                                 Monad.plus(zero, Monad.unit(5L)));
4099 +        // zero plus zero === zero
4100 +        Monad.assertZero(Monad.plus(zero, zero));
4101 +        {
4102 +            CompletableFuture<Long> f = Monad.plus(Monad.unit(5L),
4103 +                                                   Monad.unit(8L));
4104 +            // non-determinism
4105 +            assertTrue(f.get() == 5L || f.get() == 8L);
4106 +        }
4107 +
4108 +        CompletableFuture<Long> godot = new CompletableFuture<>();
4109 +        // f plus godot === f (doesn't wait for godot)
4110 +        Monad.assertFutureEquals(Monad.unit(5L),
4111 +                                 Monad.plus(Monad.unit(5L), godot));
4112 +        // godot plus f === f (doesn't wait for godot)
4113 +        Monad.assertFutureEquals(Monad.unit(5L),
4114 +                                 Monad.plus(godot, Monad.unit(5L)));
4115 +    }
4116 +
4117 +    /**
4118 +     * A single CompletableFuture with many dependents.
4119 +     * A demo of scalability - runtime is O(n).
4120 +     */
4121 +    public void testManyDependents() throws Throwable {
4122 +        final int n = 1_000;
4123 +        final CompletableFuture<Void> head = new CompletableFuture<>();
4124 +        final CompletableFuture<Void> complete = CompletableFuture.completedFuture((Void)null);
4125 +        final AtomicInteger count = new AtomicInteger(0);
4126 +        for (int i = 0; i < n; i++) {
4127 +            head.thenRun(() -> count.getAndIncrement());
4128 +            head.thenAccept((x) -> count.getAndIncrement());
4129 +            head.thenApply((x) -> count.getAndIncrement());
4130 +
4131 +            head.runAfterBoth(complete, () -> count.getAndIncrement());
4132 +            head.thenAcceptBoth(complete, (x, y) -> count.getAndIncrement());
4133 +            head.thenCombine(complete, (x, y) -> count.getAndIncrement());
4134 +            complete.runAfterBoth(head, () -> count.getAndIncrement());
4135 +            complete.thenAcceptBoth(head, (x, y) -> count.getAndIncrement());
4136 +            complete.thenCombine(head, (x, y) -> count.getAndIncrement());
4137 +
4138 +            head.runAfterEither(new CompletableFuture<Void>(), () -> count.getAndIncrement());
4139 +            head.acceptEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement());
4140 +            head.applyToEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement());
4141 +            new CompletableFuture<Void>().runAfterEither(head, () -> count.getAndIncrement());
4142 +            new CompletableFuture<Void>().acceptEither(head, (x) -> count.getAndIncrement());
4143 +            new CompletableFuture<Void>().applyToEither(head, (x) -> count.getAndIncrement());
4144 +        }
4145 +        head.complete(null);
4146 +        assertEquals(5 * 3 * n, count.get());
4147 +    }
4148 +
4149 + //     static <U> U join(CompletionStage<U> stage) {
4150 + //         CompletableFuture<U> f = new CompletableFuture<>();
4151 + //         stage.whenComplete((v, ex) -> {
4152 + //             if (ex != null) f.completeExceptionally(ex); else f.complete(v);
4153 + //         });
4154 + //         return f.join();
4155 + //     }
4156 +
4157 + //     static <U> boolean isDone(CompletionStage<U> stage) {
4158 + //         CompletableFuture<U> f = new CompletableFuture<>();
4159 + //         stage.whenComplete((v, ex) -> {
4160 + //             if (ex != null) f.completeExceptionally(ex); else f.complete(v);
4161 + //         });
4162 + //         return f.isDone();
4163 + //     }
4164 +
4165 + //     static <U> U join2(CompletionStage<U> stage) {
4166 + //         return stage.toCompletableFuture().copy().join();
4167 + //     }
4168 +
4169 + //     static <U> boolean isDone2(CompletionStage<U> stage) {
4170 + //         return stage.toCompletableFuture().copy().isDone();
4171 + //     }
4172 +
4173   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines