AsyncResult properly propagates execution exception

Issue: SPR-14249
(cherry picked from commit 1b1aac9)
This commit is contained in:
Juergen Hoeller
2016-05-05 20:40:30 +02:00
parent 2dbc8b0381
commit 5fc0d43852
2 changed files with 101 additions and 5 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import org.springframework.util.concurrent.SuccessCallback;
* to the caller.
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
* @since 3.0
* @see Async
* @see #forValue(Object)
@@ -102,11 +103,17 @@ public class AsyncResult<V> implements ListenableFuture<V> {
@Override
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback) {
try {
successCallback.onSuccess(this.value);
if (this.executionException != null) {
Throwable cause = this.executionException.getCause();
failureCallback.onFailure(cause != null ? cause : this.executionException);
}
catch (Throwable ex) {
failureCallback.onFailure(ex);
else {
try {
successCallback.onSuccess(this.value);
}
catch (Throwable ex) {
failureCallback.onFailure(ex);
}
}
}