Description
Alexis Terrat opened SPR-14298 and commented
Hi,
I encountered a bug using a SettableListenableFuture.
When I call future.setException() with a Throwable that is not an Exception, it is set as a result instead. So, it raises a ClassCastException. See the samples below.
And sorry if this is a duplicate btw :)
sample 1 :
-
code :
SettableListenableFuture<String> future = new SettableListenableFuture<>();
Consumer<String> printRes = res -> System.out.println("success " + res);
Consumer<Throwable> printErr = err -> System.out.println("failure " + err);
future.addCallback(printRes::accept, printErr::accept);
future.setException(new Throwable("test")); -
expected output :
failure java.lang.Throwable: test -
actual output :
failure java.lang.ClassCastException: java.lang.Throwable cannot be cast to java.lang.String
sample 2 :
-
code :
SettableListenableFuture<Throwable> future = new SettableListenableFuture<>();
Consumer<Throwable> printRes = res -> System.out.println("success " + res);
Consumer<Throwable> printErr = err -> System.out.println("failure " + err);
future.addCallback(printRes::accept, printErr::accept);
future.setException(new Throwable("test")); -
expected output :
failure java.lang.Throwable: test -
actual output :
success java.lang.Throwable: test
Affects: 4.2.5
Referenced from: commits cc77588, a979885
Backported to: 4.2.7