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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user