--- jsr166/src/jsr166e/CompletableFuture.java 2013/02/05 19:54:06 1.8 +++ jsr166/src/jsr166e/CompletableFuture.java 2013/03/17 18:23:59 1.15 @@ -380,7 +380,7 @@ public class CompletableFuture implem /* ------------- Async tasks -------------- */ /** - * A tagging interface identifying asynchronous tasks produced by + * A marker interface identifying asynchronous tasks produced by * {@code async} methods. This may be useful for monitoring, * debugging, and tracking asynchronous activities. */ @@ -1319,19 +1319,18 @@ public class CompletableFuture implem Object r; Throwable ex, cause; if ((r = result) == null && (r = waitingGet(true)) == null) throw new InterruptedException(); - if (r instanceof AltResult) { - if ((ex = ((AltResult)r).ex) != null) { - if (ex instanceof CancellationException) - throw (CancellationException)ex; - if ((ex instanceof CompletionException) && - (cause = ex.getCause()) != null) - ex = cause; - throw new ExecutionException(ex); - } - return null; + if (!(r instanceof AltResult)) { + @SuppressWarnings("unchecked") T tr = (T) r; + return tr; } - @SuppressWarnings("unchecked") T tr = (T) r; - return tr; + if ((ex = ((AltResult)r).ex) == null) + return null; + if (ex instanceof CancellationException) + throw (CancellationException)ex; + if ((ex instanceof CompletionException) && + (cause = ex.getCause()) != null) + ex = cause; + throw new ExecutionException(ex); } /** @@ -1356,19 +1355,18 @@ public class CompletableFuture implem throw new InterruptedException(); if ((r = result) == null) r = timedAwaitDone(nanos); - if (r instanceof AltResult) { - if ((ex = ((AltResult)r).ex) != null) { - if (ex instanceof CancellationException) - throw (CancellationException)ex; - if ((ex instanceof CompletionException) && - (cause = ex.getCause()) != null) - ex = cause; - throw new ExecutionException(ex); - } - return null; + if (!(r instanceof AltResult)) { + @SuppressWarnings("unchecked") T tr = (T) r; + return tr; } - @SuppressWarnings("unchecked") T tr = (T) r; - return tr; + if ((ex = ((AltResult)r).ex) == null) + return null; + if (ex instanceof CancellationException) + throw (CancellationException)ex; + if ((ex instanceof CompletionException) && + (cause = ex.getCause()) != null) + ex = cause; + throw new ExecutionException(ex); } /** @@ -1389,18 +1387,17 @@ public class CompletableFuture implem Object r; Throwable ex; if ((r = result) == null) r = waitingGet(false); - if (r instanceof AltResult) { - if ((ex = ((AltResult)r).ex) != null) { - if (ex instanceof CancellationException) - throw (CancellationException)ex; - if (ex instanceof CompletionException) - throw (CompletionException)ex; - throw new CompletionException(ex); - } - return null; + if (!(r instanceof AltResult)) { + @SuppressWarnings("unchecked") T tr = (T) r; + return tr; } - @SuppressWarnings("unchecked") T tr = (T) r; - return tr; + if ((ex = ((AltResult)r).ex) == null) + return null; + if (ex instanceof CancellationException) + throw (CancellationException)ex; + if (ex instanceof CompletionException) + throw (CompletionException)ex; + throw new CompletionException(ex); } /** @@ -1417,18 +1414,17 @@ public class CompletableFuture implem Object r; Throwable ex; if ((r = result) == null) return valueIfAbsent; - if (r instanceof AltResult) { - if ((ex = ((AltResult)r).ex) != null) { - if (ex instanceof CancellationException) - throw (CancellationException)ex; - if (ex instanceof CompletionException) - throw (CompletionException)ex; - throw new CompletionException(ex); - } - return null; + if (!(r instanceof AltResult)) { + @SuppressWarnings("unchecked") T tr = (T) r; + return tr; } - @SuppressWarnings("unchecked") T tr = (T) r; - return tr; + if ((ex = ((AltResult)r).ex) == null) + return null; + if (ex instanceof CancellationException) + throw (CancellationException)ex; + if (ex instanceof CompletionException) + throw (CompletionException)ex; + throw new CompletionException(ex); } /** @@ -1792,7 +1788,6 @@ public class CompletableFuture implem * @param executor the executor to use for asynchronous execution * @return the new CompletableFuture */ - public CompletableFuture thenCombineAsync(CompletableFuture other, BiFun fn, Executor executor) { @@ -2559,7 +2554,6 @@ public class CompletableFuture implem * * @param fn the function to use to compute the value of the * returned CompletableFuture - * @return the new CompletableFuture */ public CompletableFuture handle(BiFun fn) { @@ -2633,17 +2627,16 @@ public class CompletableFuture implem */ public boolean isCancelled() { Object r; - return ((r = result) != null && - (r instanceof AltResult) && - (((AltResult)r).ex instanceof CancellationException)); + return ((r = result) instanceof AltResult) && + (((AltResult)r).ex instanceof CancellationException); } /** * Forcibly sets or resets the value subsequently returned by - * method get() and related methods, whether or not already - * completed. This method is designed for use only in error - * recovery actions, and even in such situations may result in - * ongoing dependent completions using established versus + * method {@link #get()} and related methods, whether or not + * already completed. This method is designed for use only in + * error recovery actions, and even in such situations may result + * in ongoing dependent completions using established versus * overwritten outcomes. * * @param value the completion value @@ -2654,9 +2647,9 @@ public class CompletableFuture implem } /** - * Forcibly causes subsequent invocations of method get() and - * related methods to throw the given exception, whether or not - * already completed. This method is designed for use only in + * Forcibly causes subsequent invocations of method {@link #get()} + * and related methods to throw the given exception, whether or + * not already completed. This method is designed for use only in * recovery actions, and even in such situations may result in * ongoing dependent completions using established versus * overwritten outcomes.