Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SettableListenableFuture.setException(Throwable) doesn't work for Error [SPR-14298] #18870

Closed
spring-projects-issues opened this issue May 23, 2016 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3 GA milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants