From 9466b62f54a359d335a998fd549be4d0a6252197 Mon Sep 17 00:00:00 2001 From: jlavallee Date: Mon, 18 Jun 2018 13:18:31 -0700 Subject: [PATCH] Removed special-casing UndeclaredThrowableException in Futures.transform() RELNOTES=`util.concurrent`: Removed special-casing `UndeclaredThrowableException` in `Futures.transform()`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201046764 --- .../common/util/concurrent/FuturesTransformAsyncTest.java | 7 +++---- .../common/util/concurrent/FuturesTransformTest.java | 6 ++++-- .../common/util/concurrent/AbstractTransformFuture.java | 6 ------ .../common/util/concurrent/FuturesTransformAsyncTest.java | 7 +++---- .../common/util/concurrent/FuturesTransformTest.java | 6 ++++-- .../common/util/concurrent/AbstractTransformFuture.java | 6 ------ 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java b/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java index f318fdda0eae..24990200df04 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java @@ -22,7 +22,6 @@ import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture; -import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -58,7 +57,7 @@ protected String getSuccessfulResult() { private class ChainingFunction implements AsyncFunction { @Override - public ListenableFuture apply(Integer input) { + public ListenableFuture apply(Integer input) throws Exception { switch (input) { case VALID_INPUT_DATA: outputFuture.set(RESULT_DATA); @@ -69,8 +68,8 @@ public ListenableFuture apply(Integer input) { funcIsWaitingLatch.countDown(); awaitUninterruptibly(funcCompletionLatch); break; - default: - throw new UndeclaredThrowableException(EXCEPTION); + case EXCEPTION_DATA: + throw EXCEPTION; } return outputFuture; } diff --git a/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java b/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java index ba8ac6eb1f24..9f211dd8b8b2 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java @@ -29,6 +29,8 @@ */ public class FuturesTransformTest extends AbstractChainedListenableFutureTest { private static final String RESULT_DATA = "SUCCESS"; + private static final UndeclaredThrowableException WRAPPED_EXCEPTION = + new UndeclaredThrowableException(EXCEPTION); @Override protected ListenableFuture buildChainingFuture(ListenableFuture inputFuture) { @@ -46,13 +48,13 @@ public String apply(Integer input) { if (input.intValue() == VALID_INPUT_DATA) { return RESULT_DATA; } else { - throw new UndeclaredThrowableException(EXCEPTION); + throw WRAPPED_EXCEPTION; } } } public void testFutureGetThrowsFunctionException() throws Exception { inputFuture.set(EXCEPTION_DATA); - listener.assertException(EXCEPTION); + listener.assertException(WRAPPED_EXCEPTION); } } diff --git a/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java b/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java index 986a0831e02a..437f37733007 100644 --- a/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java @@ -21,7 +21,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Function; import com.google.errorprone.annotations.ForOverride; -import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -109,10 +108,6 @@ public final void run() { T transformResult; try { transformResult = doTransform(localFunction, sourceResult); - } catch (UndeclaredThrowableException e) { - // Set the cause of the exception as this future's exception. - setException(e.getCause()); - return; } catch (Throwable t) { // This exception is irrelevant in this thread, but useful for the client. setException(t); @@ -237,7 +232,6 @@ private static final class TransformFuture @NullableDecl O doTransform(Function function, @NullableDecl I input) { return function.apply(input); - // TODO(lukes): move the UndeclaredThrowable catch block here? } @Override diff --git a/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java b/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java index f318fdda0eae..24990200df04 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java @@ -22,7 +22,6 @@ import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture; -import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -58,7 +57,7 @@ protected String getSuccessfulResult() { private class ChainingFunction implements AsyncFunction { @Override - public ListenableFuture apply(Integer input) { + public ListenableFuture apply(Integer input) throws Exception { switch (input) { case VALID_INPUT_DATA: outputFuture.set(RESULT_DATA); @@ -69,8 +68,8 @@ public ListenableFuture apply(Integer input) { funcIsWaitingLatch.countDown(); awaitUninterruptibly(funcCompletionLatch); break; - default: - throw new UndeclaredThrowableException(EXCEPTION); + case EXCEPTION_DATA: + throw EXCEPTION; } return outputFuture; } diff --git a/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java b/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java index ba8ac6eb1f24..9f211dd8b8b2 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java @@ -29,6 +29,8 @@ */ public class FuturesTransformTest extends AbstractChainedListenableFutureTest { private static final String RESULT_DATA = "SUCCESS"; + private static final UndeclaredThrowableException WRAPPED_EXCEPTION = + new UndeclaredThrowableException(EXCEPTION); @Override protected ListenableFuture buildChainingFuture(ListenableFuture inputFuture) { @@ -46,13 +48,13 @@ public String apply(Integer input) { if (input.intValue() == VALID_INPUT_DATA) { return RESULT_DATA; } else { - throw new UndeclaredThrowableException(EXCEPTION); + throw WRAPPED_EXCEPTION; } } } public void testFutureGetThrowsFunctionException() throws Exception { inputFuture.set(EXCEPTION_DATA); - listener.assertException(EXCEPTION); + listener.assertException(WRAPPED_EXCEPTION); } } diff --git a/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java b/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java index e6691500d7f8..a37ff8edb633 100644 --- a/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java +++ b/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java @@ -21,7 +21,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Function; import com.google.errorprone.annotations.ForOverride; -import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -109,10 +108,6 @@ public final void run() { T transformResult; try { transformResult = doTransform(localFunction, sourceResult); - } catch (UndeclaredThrowableException e) { - // Set the cause of the exception as this future's exception. - setException(e.getCause()); - return; } catch (Throwable t) { // This exception is irrelevant in this thread, but useful for the client. setException(t); @@ -236,7 +231,6 @@ private static final class TransformFuture @Nullable O doTransform(Function function, @Nullable I input) { return function.apply(input); - // TODO(lukes): move the UndeclaredThrowable catch block here? } @Override