This is finally ready for integration. Going once... going twice...
Updated webrev and specdiff:
http://cr.openjdk.java.net/~chegar/8005696/ver.02/
Doug,
I just finalized the jtreg test, and found a small issue. Please find
below a suggested change (included in the webrev), and a small test to
demonstrate. Since the jtreg test reproduces the problem, the small test
is just for your convenience to validate the change, etc.
>: cvs diff -u -U5 CompletableFuture.java
Index: CompletableFuture.java
===================================================================
RCS file:
/home/jsr166/jsr166/jsr166/src/main/java/util/concurrent/CompletableFuture.java,v
retrieving revision 1.80
diff -u -U 5 -r1.80 CompletableFuture.java
--- CompletableFuture.java 1 Apr 2013 20:16:05 -0000 1.80
+++ CompletableFuture.java 4 Apr 2013 13:34:58 -0000
@@ -2812,12 +2812,15 @@
}
if (dst == null)
dst = new CompletableFuture<U>();
}
}
- if (e == null && ex != null)
+ if (ex != null) {
+ if (dst == null)
+ dst = new CompletableFuture<U>();
dst.internalComplete(null, ex);
+ }
}
helpPostComplete();
dst.helpPostComplete();
return dst;
}
Here is a test to reproduce:
:> cat ThenCompose.java
import java.util.concurrent.CompletableFuture;
public class ThenCompose {
public static void main(String[] args) throws Exception {
CompletableFuture<?> cf1 = CompletableFuture.supplyAsync(() ->
{ throw new RuntimeException(); });
CompletableFuture<Void> cf2 = cf1.thenCompose((x) ->
{ return new
CompletableFuture<Void>(); });
}
}
:>
/export/home/chris/repos/jdk8/tl/cf/build/solaris-sparc-normal-server-release/jdk/bin/java
ThenCompose
Exception in thread "main" java.lang.NullPointerException
at
java.util.concurrent.CompletableFuture.doCompose(CompletableFuture.java:2847)
at
java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2756)
at ThenCompose.main(ThenCompose.java:8)
lection
-Chris.
On 03/27/2013 07:46 PM, Doug Lea wrote:
On 03/23/13 07:08, Doug Lea wrote:
There was a signature mismatch between the public
public static CompletableFuture<Void> anyOf(CompletableFuture<?>...
cfs)
and the internal method performing most of the work:
private static CompletableFuture<?> anyTree(...)
("<Void>" and "<?>" are subtly different.)
Thanks to Martin especially for knocking some sense into me
about this. The type signature *was* incompatible, but
changing to <Void> rather the <Object> made this updated
version less useful (it could only return indication, not
result). So it is now updated with a signature-correct
version of anyOf with its original semantics.
Additionally, while being slightly disruptive anyway:
This class was lacking a little convenience method found in
other Future-based frameworks that surely will be requested.
So now added:
/**
* Returns a new CompletableFuture that is already completed with
* the given value.
*
* @param value the value
* @return the completed CompletableFuture
*/
public static <U> CompletableFuture<U> completedFuture(U value)