-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
8
ADDITIONAL SYSTEM INFORMATION :
The has been reproduced on openjdk-8u232-b09 on Windows 10, openjdk-11.0.3 on Ubuntu 18.04 and openjdk-11.0.2 on Windows 10.
A DESCRIPTION OF THE PROBLEM :
According to the documentation on CompletableFuture.whenComplete(), this method "Returns a new CompletionStage with the same result or exception as this stage". However, subsequent invocations of whenComplete() provide a different exception. It has been wrapped in a CompletionException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following test case produces two different stack traces for each of the whenComplete invocations:
@Test
public void testWhenCompleteKeepExceptionalResultIntact() {
RuntimeException expected = new RuntimeException("original");
CompletableFuture<?> result = new CompletableFuture<>();
result.whenComplete((r, e) -> System.out.println(e.toString()))
.whenComplete((r, e) -> System.out.println(e.toString()));
result.completeExceptionally(expected);
}
@Test
public void testThenApplyKeepExceptionalResultIntact() {
RuntimeException expected = new RuntimeException("original");
CompletableFuture<?> result = new CompletableFuture<>();
result.thenApply(e -> e)
.whenComplete((r, e) -> System.out.println(e.toString()));
result.completeExceptionally(expected);
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For the first testcase (with whenComplete):
java.lang.RuntimeException: original
java.lang.RuntimeException: original
For the second test (with thenApply)
java.lang.RuntimeException: original
ACTUAL -
For the first testcase (with whenComplete):
java.lang.RuntimeException: original
java.util.concurrent.CompletionException: java.lang.RuntimeException: original
For the second test (with thenApply)
java.util.concurrent.CompletionException: java.lang.RuntimeException: original
FREQUENCY : always
The has been reproduced on openjdk-8u232-b09 on Windows 10, openjdk-11.0.3 on Ubuntu 18.04 and openjdk-11.0.2 on Windows 10.
A DESCRIPTION OF THE PROBLEM :
According to the documentation on CompletableFuture.whenComplete(), this method "Returns a new CompletionStage with the same result or exception as this stage". However, subsequent invocations of whenComplete() provide a different exception. It has been wrapped in a CompletionException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following test case produces two different stack traces for each of the whenComplete invocations:
@Test
public void testWhenCompleteKeepExceptionalResultIntact() {
RuntimeException expected = new RuntimeException("original");
CompletableFuture<?> result = new CompletableFuture<>();
result.whenComplete((r, e) -> System.out.println(e.toString()))
.whenComplete((r, e) -> System.out.println(e.toString()));
result.completeExceptionally(expected);
}
@Test
public void testThenApplyKeepExceptionalResultIntact() {
RuntimeException expected = new RuntimeException("original");
CompletableFuture<?> result = new CompletableFuture<>();
result.thenApply(e -> e)
.whenComplete((r, e) -> System.out.println(e.toString()));
result.completeExceptionally(expected);
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For the first testcase (with whenComplete):
java.lang.RuntimeException: original
java.lang.RuntimeException: original
For the second test (with thenApply)
java.lang.RuntimeException: original
ACTUAL -
For the first testcase (with whenComplete):
java.lang.RuntimeException: original
java.util.concurrent.CompletionException: java.lang.RuntimeException: original
For the second test (with thenApply)
java.util.concurrent.CompletionException: java.lang.RuntimeException: original
FREQUENCY : always