JDK-8056249 : Improve CompletableFuture resource usage
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-08-28
  • Updated: 2016-06-13
  • Resolved: 2014-09-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u40Fixed 9 b30Fixed
Related Reports
Duplicate :  
There have been many improvements to the implementation of j.u.c.CompletableFuture in the jsr 166 repo:


Enhancements include better resource handling for large completion chains (including branched chains) and improved internal restructuring of the implementation.
@Volker you are right, the test assertion is incorrect. The incorrect part of the test has been removed and fixed in JCK 8a and JCK 9. If an implementation of CompletableFuture encounters this test failure with JCK 8, then a test challenge should be filed, and the section of the test excluded. JCK 8a and JCK 9 imported the "fixed" test from the 166 CVS, and this resolves the problem that you described, but the "fixed" test had a new separate issue which JDK-8062535 tracks. Some of the comments in this bug, and others, are a little confused and comment on different versions of the test in different locations, JCK 8, JCK 8a-ea, JCK 9-ea, and the 166 CVS, at different points in time. Note: there are several bugs tracking these issues, some open and some that are not, the JCK issues. The latest version of the CF test in JCK 8a, JCK 9, and the 166 CVS has no known issues. I assume 8u40 will be certified with JCK 8a.

This change is definitely at least one of the reasons for the failing of api/java_util/concurrent/CompletableFuture/index.html#CompletableFuture. As far as I can see, the part of the test which fails is not part of the jsr166 CVS tests. That's probably the reason why nobody saw the failure before. I've attached a stripped down stand alone version of the failing test. The main part looks as follows: CompletableFuture<Integer> f = new CompletableFuture<>(); CompletableFuture<Integer> f2 = new CompletableFuture<>(); f2.completeExceptionally(new CFException()); CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); f.complete(one); checkCompletedWithWrappedCFException(g); The test checks that the CompletableFuture 'g' will be completed with an exception. From my limited understanding of j.u.c.CompletableFuture I'd say that this test is wrong, because there's no guarantee which of the two CompletableFutures 'f' or 'f2' is executed first. It seems the with the old implementation 'f2' was executed frst (and it completed with an exception) but now, after 8056249, 'f' seems to be executed first which completes regularly. Notice that the attached test case will fail with both 8u-dev and 9-dev after the integration of 8056249, no difference what java.util.concurrent.ForkJoinPool.common.parallelism is set to. So I'm pretty sure that the failure we're talking about here is not caused by JDK-8062535. I'd propose to quickly fix api/java_util/concurrent/CompletableFuture/index.html#CompletableFuture, otherwise it isn't possible to certify 8u40. Otherwise 8056249 would have to be backed-out from 8u-dev and 8u40.

Stand alone test case which is similar to the part of the CompletableFuture JCK test which fails after 8056249.

I agree with Dmitry. CompletableFuture and CompletableFutureTest were developed together in jsr166 CVS. CompletableFuture has no known bugs, and CompletableFutureTest was just fixed for JDK-8062535 in jsr166 CVS.

Seems that the reason of the test api/java_util/concurrent/CompletableFuture/index.html#CompletableFuture failure is JDK-8062535, and not this issue

More details please. We don't see failures running jsr166 CVS tests on LInux.

Failed JCK test: api/java_util/concurrent/CompletableFuture/index.html#CompletableFuture