Skip to content

Commit 9466b62

Browse files
jlavalleecgdecker
authored andcommitted
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
1 parent 39fda5d commit 9466b62

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly;
2323

2424
import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
25-
import java.lang.reflect.UndeclaredThrowableException;
2625
import java.util.concurrent.CancellationException;
2726
import java.util.concurrent.CountDownLatch;
2827
import java.util.concurrent.ExecutionException;
@@ -58,7 +57,7 @@ protected String getSuccessfulResult() {
5857

5958
private class ChainingFunction implements AsyncFunction<Integer, String> {
6059
@Override
61-
public ListenableFuture<String> apply(Integer input) {
60+
public ListenableFuture<String> apply(Integer input) throws Exception {
6261
switch (input) {
6362
case VALID_INPUT_DATA:
6463
outputFuture.set(RESULT_DATA);
@@ -69,8 +68,8 @@ public ListenableFuture<String> apply(Integer input) {
6968
funcIsWaitingLatch.countDown();
7069
awaitUninterruptibly(funcCompletionLatch);
7170
break;
72-
default:
73-
throw new UndeclaredThrowableException(EXCEPTION);
71+
case EXCEPTION_DATA:
72+
throw EXCEPTION;
7473
}
7574
return outputFuture;
7675
}

android/guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
public class FuturesTransformTest extends AbstractChainedListenableFutureTest<String> {
3131
private static final String RESULT_DATA = "SUCCESS";
32+
private static final UndeclaredThrowableException WRAPPED_EXCEPTION =
33+
new UndeclaredThrowableException(EXCEPTION);
3234

3335
@Override
3436
protected ListenableFuture<String> buildChainingFuture(ListenableFuture<Integer> inputFuture) {
@@ -46,13 +48,13 @@ public String apply(Integer input) {
4648
if (input.intValue() == VALID_INPUT_DATA) {
4749
return RESULT_DATA;
4850
} else {
49-
throw new UndeclaredThrowableException(EXCEPTION);
51+
throw WRAPPED_EXCEPTION;
5052
}
5153
}
5254
}
5355

5456
public void testFutureGetThrowsFunctionException() throws Exception {
5557
inputFuture.set(EXCEPTION_DATA);
56-
listener.assertException(EXCEPTION);
58+
listener.assertException(WRAPPED_EXCEPTION);
5759
}
5860
}

android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.annotations.GwtCompatible;
2222
import com.google.common.base.Function;
2323
import com.google.errorprone.annotations.ForOverride;
24-
import java.lang.reflect.UndeclaredThrowableException;
2524
import java.util.concurrent.CancellationException;
2625
import java.util.concurrent.ExecutionException;
2726
import java.util.concurrent.Executor;
@@ -109,10 +108,6 @@ public final void run() {
109108
T transformResult;
110109
try {
111110
transformResult = doTransform(localFunction, sourceResult);
112-
} catch (UndeclaredThrowableException e) {
113-
// Set the cause of the exception as this future's exception.
114-
setException(e.getCause());
115-
return;
116111
} catch (Throwable t) {
117112
// This exception is irrelevant in this thread, but useful for the client.
118113
setException(t);
@@ -237,7 +232,6 @@ private static final class TransformFuture<I, O>
237232
@NullableDecl
238233
O doTransform(Function<? super I, ? extends O> function, @NullableDecl I input) {
239234
return function.apply(input);
240-
// TODO(lukes): move the UndeclaredThrowable catch block here?
241235
}
242236

243237
@Override

guava-tests/test/com/google/common/util/concurrent/FuturesTransformAsyncTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly;
2323

2424
import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
25-
import java.lang.reflect.UndeclaredThrowableException;
2625
import java.util.concurrent.CancellationException;
2726
import java.util.concurrent.CountDownLatch;
2827
import java.util.concurrent.ExecutionException;
@@ -58,7 +57,7 @@ protected String getSuccessfulResult() {
5857

5958
private class ChainingFunction implements AsyncFunction<Integer, String> {
6059
@Override
61-
public ListenableFuture<String> apply(Integer input) {
60+
public ListenableFuture<String> apply(Integer input) throws Exception {
6261
switch (input) {
6362
case VALID_INPUT_DATA:
6463
outputFuture.set(RESULT_DATA);
@@ -69,8 +68,8 @@ public ListenableFuture<String> apply(Integer input) {
6968
funcIsWaitingLatch.countDown();
7069
awaitUninterruptibly(funcCompletionLatch);
7170
break;
72-
default:
73-
throw new UndeclaredThrowableException(EXCEPTION);
71+
case EXCEPTION_DATA:
72+
throw EXCEPTION;
7473
}
7574
return outputFuture;
7675
}

guava-tests/test/com/google/common/util/concurrent/FuturesTransformTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
public class FuturesTransformTest extends AbstractChainedListenableFutureTest<String> {
3131
private static final String RESULT_DATA = "SUCCESS";
32+
private static final UndeclaredThrowableException WRAPPED_EXCEPTION =
33+
new UndeclaredThrowableException(EXCEPTION);
3234

3335
@Override
3436
protected ListenableFuture<String> buildChainingFuture(ListenableFuture<Integer> inputFuture) {
@@ -46,13 +48,13 @@ public String apply(Integer input) {
4648
if (input.intValue() == VALID_INPUT_DATA) {
4749
return RESULT_DATA;
4850
} else {
49-
throw new UndeclaredThrowableException(EXCEPTION);
51+
throw WRAPPED_EXCEPTION;
5052
}
5153
}
5254
}
5355

5456
public void testFutureGetThrowsFunctionException() throws Exception {
5557
inputFuture.set(EXCEPTION_DATA);
56-
listener.assertException(EXCEPTION);
58+
listener.assertException(WRAPPED_EXCEPTION);
5759
}
5860
}

guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.annotations.GwtCompatible;
2222
import com.google.common.base.Function;
2323
import com.google.errorprone.annotations.ForOverride;
24-
import java.lang.reflect.UndeclaredThrowableException;
2524
import java.util.concurrent.CancellationException;
2625
import java.util.concurrent.ExecutionException;
2726
import java.util.concurrent.Executor;
@@ -109,10 +108,6 @@ public final void run() {
109108
T transformResult;
110109
try {
111110
transformResult = doTransform(localFunction, sourceResult);
112-
} catch (UndeclaredThrowableException e) {
113-
// Set the cause of the exception as this future's exception.
114-
setException(e.getCause());
115-
return;
116111
} catch (Throwable t) {
117112
// This exception is irrelevant in this thread, but useful for the client.
118113
setException(t);
@@ -236,7 +231,6 @@ private static final class TransformFuture<I, O>
236231
@Nullable
237232
O doTransform(Function<? super I, ? extends O> function, @Nullable I input) {
238233
return function.apply(input);
239-
// TODO(lukes): move the UndeclaredThrowable catch block here?
240234
}
241235

242236
@Override

0 commit comments

Comments
 (0)