Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions