Skip to content

Commit

Permalink
BlockingUtils should not assume the cause of ExecutionException is no…
Browse files Browse the repository at this point in the history
…t null (#873)

__Motivation__

BlockingUtils should not assume the cause of ExecutionException is not null.

__Modifications__

Add method `BlockingUtils.executionExceptionCause` that returns nonnull
cause or original throwable.

__Result__

Fixes #870.
  • Loading branch information
volyx authored and idelpivnitskiy committed Nov 22, 2019
1 parent fc5be20 commit 33574d1
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -97,7 +97,7 @@ static <T> T futureGetCancelOnInterrupt(Future<T> future) throws Exception {
future.cancel(false);
throw e;
} catch (ExecutionException e) {
return throwException(e.getCause());
return throwException(executionExceptionCause(e));
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ static <T> T blockingInvocation(Single<T> source) throws Exception {
try {
return source.toFuture().get();
} catch (final ExecutionException e) {
return throwException(e.getCause());
return throwException(executionExceptionCause(e));
}
}

Expand All @@ -160,7 +160,11 @@ static void blockingInvocation(Completable source) throws Exception {
try {
source.toFuture().get();
} catch (final ExecutionException e) {
throwException(e.getCause());
throwException(executionExceptionCause(e));
}
}

private static Throwable executionExceptionCause(ExecutionException original) {
return (original.getCause() != null) ? original.getCause() : original;
}
}

0 comments on commit 33574d1

Please sign in to comment.