Refine ListenableFutureCallback policy for exceptions

This change updates all cases where callbacks are invoked to catch and
suppress errors (since there is not match to do with and error from
a callback be it success or failure).

Also updated is the contract itself to clarify this and emphasize the
callbacks are really notifications for the outcome of the
ListenableFuture not the callbacks themselves.

Issue: SPR-13785
This commit is contained in:
Rossen Stoyanchev
2016-01-14 17:49:01 -05:00
parent 037f351efd
commit 3dae3fd8a9
8 changed files with 78 additions and 39 deletions

View File

@@ -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)
@@ -103,10 +104,16 @@ 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);
}
else {
successCallback.onSuccess(this.value);
}
}
catch (Throwable ex) {
failureCallback.onFailure(ex);
// Ignore
}
}