Skip to content

Exception not thrown by OnFailure() when using ListenableFutureCallback [SPR-12797] #17394

@spring-projects-issues

Description

@spring-projects-issues

Antonio Parolini opened SPR-12797 and commented

In class AsyncExecutionAspectSupport, line 171:

The check to see if the method return type is of type Futur and descendants is inverted. It dosen't rethrow the original exception in case of ListenableFuture
It should be

if (Future.class.isAssignableFrom(method.getReturnType())) {

Exemple code when using ListenableFuture with asyc:

@Async((Application.MASS_THREAD_EXECUTOR))
public ListenableFuture<ImportJob> importOneJobMassAsync(ImportJob importJob, UTILSessionData sessionData) {
    //throw new IllegalArgumentException("test execption");
    importPartialData(importJob, sessionData);
    return new AsyncResult<>(importJob);
}
              futur.addCallback(
                        new ListenableFutureCallback<ImportJob>() {
                            /**
                             * On success is called also when we cancel the execussion pool
                             * But Import Job will be null
                            */

                            @Override
                            public void onSuccess(ImportJob importJob) {
                                UTILLog.logInfo(this.getClass().getName(), "futur.get finished");
                           }

                            /**
                             * This is called only when the job has been canceled
                             * @param ex
                             */
                            @Override
                            public void onFailure(Throwable ex) {
                                UTILLog.logError(this.getClass().getName(), "Job in error:" + ex.getMessage(), ex);
                            }
                        });
  

Affects: 4.1.5

Attachments:

Issue Links:

Referenced from: commits 406adb3, 8f8a859

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions