diff --git a/servicetalk-concurrent-api-internal/src/main/java/io/servicetalk/concurrent/api/internal/BlockingUtils.java b/servicetalk-concurrent-api-internal/src/main/java/io/servicetalk/concurrent/api/internal/BlockingUtils.java index ae5b045384..8cf982ae19 100644 --- a/servicetalk-concurrent-api-internal/src/main/java/io/servicetalk/concurrent/api/internal/BlockingUtils.java +++ b/servicetalk-concurrent-api-internal/src/main/java/io/servicetalk/concurrent/api/internal/BlockingUtils.java @@ -21,7 +21,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import static io.servicetalk.utils.internal.ThrowableUtils.throwException; +import static io.servicetalk.utils.internal.PlatformDependent.throwException; /** * Common utility functions to unwrap {@link ExecutionException} from async operations. @@ -50,7 +50,7 @@ public static T futureGetCancelOnInterrupt(Future future) throws Exceptio future.cancel(false); throw e; } catch (ExecutionException e) { - return throwException(unwrapExecutionException(e)); + return throwException(executionExceptionCause(e)); } } @@ -69,7 +69,7 @@ public static T blockingInvocation(Single source) throws Exception { try { return source.toFuture().get(); } catch (final ExecutionException e) { - return throwException(unwrapExecutionException(e)); + return throwException(executionExceptionCause(e)); } } @@ -86,31 +86,11 @@ public static void blockingInvocation(Completable source) throws Exception { try { source.toFuture().get(); } catch (final ExecutionException e) { - throwException(unwrapExecutionException(e)); + throwException(executionExceptionCause(e)); } } - private static Throwable unwrapExecutionException(ExecutionException ee) { - final Throwable cause = ee.getCause(); - if (cause == null) { - return ee; - } - cause.addSuppressed(new SuppressedExecutionException(ee)); - return cause; - } - - private static final class SuppressedExecutionException extends ExecutionException { - private static final long serialVersionUID = 2001711259056665126L; - - SuppressedExecutionException(final ExecutionException original) { - super("Blocking operation terminated with an error"); - setStackTrace(original.getStackTrace()); - } - - @Override - public synchronized Throwable fillInStackTrace() { - // We inherit the stack-trace from the original ExecutionException - return this; - } + private static Throwable executionExceptionCause(ExecutionException original) { + return (original.getCause() != null) ? original.getCause() : original; } } diff --git a/servicetalk-concurrent-api-internal/src/test/java/io/servicetalk/concurrent/api/internal/BlockingUtilsTest.java b/servicetalk-concurrent-api-internal/src/test/java/io/servicetalk/concurrent/api/internal/BlockingUtilsTest.java deleted file mode 100644 index 7ed5221f2d..0000000000 --- a/servicetalk-concurrent-api-internal/src/test/java/io/servicetalk/concurrent/api/internal/BlockingUtilsTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2022 Apple Inc. and the ServiceTalk project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.servicetalk.concurrent.api.internal; - -import io.servicetalk.concurrent.api.Completable; -import io.servicetalk.concurrent.api.Single; -import io.servicetalk.concurrent.internal.DeliberateException; - -import org.junit.jupiter.api.Test; - -import java.util.concurrent.ExecutionException; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.arrayWithSize; -import static org.hamcrest.Matchers.emptyArray; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.sameInstance; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class BlockingUtilsTest { - - @Test - void testSingle() { - test(t -> BlockingUtils.blockingInvocation(Single.failed(t))); - } - - @Test - void testCompletable() { - test(t -> BlockingUtils.blockingInvocation(Completable.failed(t))); - } - - private static void test(BlockingTask blockingTask) { - DeliberateException expected = new DeliberateException(); - DeliberateException e = assertThrows(DeliberateException.class, () -> blockingTask.run(expected)); - assertThat(e, is(sameInstance(expected))); - assertThat(e.getSuppressed(), is(arrayWithSize(1))); - Throwable ee = e.getSuppressed()[0]; - assertThat(ee, is(instanceOf(ExecutionException.class))); - assertThat(ee.getStackTrace(), is(not(emptyArray()))); - } - - @FunctionalInterface - private interface BlockingTask { - void run(Throwable t) throws Exception; - } -}