Different messages for CompletionException under different minor versions of Java 8 -
i different output same code snippet under different minor version of java. not able find related ticket on open jdk bug tracker.
completablefuture<string> completablefuture = new completablefuture<>(); completablefuture.complete("xxx"); completablefuture.thencompose(str -> { completablefuture<string> completablefuture1 = new completablefuture<>(); completablefuture1.completeexceptionally(new exception("hello")); return completablefuture1; }).exceptionally(ex -> { system.out.println(ex.getmessage()); return null; }).get(); output under jdk 1.8.0_25:
hello
output under jdk 1.8.0_102:
java.lang.exception: hello
is newer 1 fix or regression? related ticket?
there's bug report here discussing change. key in javadoc of completablefuture#thencompose
returns new
completionstagethat, when stage completes normally, executed stage argument supplied function. seecompletionstagedocumentation rules covering exceptional completion.
and , class documentation of completionstage
in other cases, if stage's computation terminates abruptly (unchecked) exception or error, dependent stages requiring completion complete exceptionally well, with
completionexceptionholding exception cause.
that's see here. function pass exceptionally receives completionexception holding exception completed triggering completablefuture.
the behavior see expected behavior.
you'll have unwrap cause of exceptional completion
throwable cause = ex.getcause(); // exception("hello")
Comments
Post a Comment