Skip to content

Commit edd8aed

Browse files
JakeWhartonakarnokd
authored andcommitted
Remove checked exceptions from transformer interfaces. (#4710)
These functions are for transforming the stream shape, not doing work. Any operation that would throw a checked exception should happen inside the stream, not when shaping it.
1 parent 1124dc7 commit edd8aed

File tree

13 files changed

+17
-133
lines changed

13 files changed

+17
-133
lines changed

src/main/java/io/reactivex/Completable.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,7 @@ public final Throwable blockingGet(long timeout, TimeUnit unit) {
942942
*/
943943
@SchedulerSupport(SchedulerSupport.NONE)
944944
public final Completable compose(CompletableTransformer transformer) {
945-
try {
946-
return wrap(transformer.apply(this));
947-
} catch (Throwable ex) {
948-
Exceptions.throwIfFatal(ex);
949-
throw ExceptionHelper.wrapOrThrow(ex);
950-
}
945+
return wrap(transformer.apply(this));
951946
}
952947

953948
/**

src/main/java/io/reactivex/CompletableTransformer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public interface CompletableTransformer {
2222
* Applies a function to the upstream Completable and returns a CompletableSource.
2323
* @param upstream the upstream Completable instance
2424
* @return the transformed CompletableSource instance
25-
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
26-
* into a RuntimeException
2725
*/
28-
CompletableSource apply(Completable upstream) throws Exception;
26+
CompletableSource apply(Completable upstream);
2927
}

src/main/java/io/reactivex/Flowable.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,12 +6322,7 @@ public final <U> Single<U> collectInto(final U initialItem, BiConsumer<? super U
63226322
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
63236323
@SchedulerSupport(SchedulerSupport.NONE)
63246324
public final <R> Flowable<R> compose(FlowableTransformer<T, R> composer) {
6325-
try {
6326-
return fromPublisher(composer.apply(this));
6327-
} catch (Throwable ex) {
6328-
Exceptions.throwIfFatal(ex);
6329-
throw ExceptionHelper.wrapOrThrow(ex);
6330-
}
6325+
return fromPublisher(composer.apply(this));
63316326
}
63326327

63336328
/**

src/main/java/io/reactivex/FlowableTransformer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public interface FlowableTransformer<Upstream, Downstream> {
2727
* optionally different element type.
2828
* @param upstream the upstream Flowable instance
2929
* @return the transformed Publisher instance
30-
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
31-
* into a RuntimeException
3230
*/
33-
Publisher<Downstream> apply(Flowable<Upstream> upstream) throws Exception;
31+
Publisher<Downstream> apply(Flowable<Upstream> upstream);
3432
}

src/main/java/io/reactivex/Maybe.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,12 +2010,7 @@ public final <U> Maybe<U> cast(final Class<? extends U> clazz) {
20102010
*/
20112011
@SchedulerSupport(SchedulerSupport.NONE)
20122012
public final <R> Maybe<R> compose(MaybeTransformer<T, R> transformer) {
2013-
try {
2014-
return wrap(transformer.apply(this));
2015-
} catch (Throwable ex) {
2016-
Exceptions.throwIfFatal(ex);
2017-
throw ExceptionHelper.wrapOrThrow(ex);
2018-
}
2013+
return wrap(transformer.apply(this));
20192014
}
20202015

20212016
/**

src/main/java/io/reactivex/MaybeTransformer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public interface MaybeTransformer<Upstream, Downstream> {
2525
* optionally different element type.
2626
* @param upstream the upstream Maybe instance
2727
* @return the transformed MaybeSource instance
28-
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
29-
* into a RuntimeException
3028
*/
31-
MaybeSource<Downstream> apply(Maybe<Upstream> upstream) throws Exception;
29+
MaybeSource<Downstream> apply(Maybe<Upstream> upstream);
3230
}

src/main/java/io/reactivex/Observable.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5531,15 +5531,9 @@ public final <U> Single<U> collectInto(final U initialValue, BiConsumer<? super
55315531
*/
55325532
@SchedulerSupport(SchedulerSupport.NONE)
55335533
public final <R> Observable<R> compose(ObservableTransformer<T, R> composer) {
5534-
try {
5535-
return wrap(composer.apply(this));
5536-
} catch (Throwable ex) {
5537-
Exceptions.throwIfFatal(ex);
5538-
throw ExceptionHelper.wrapOrThrow(ex);
5539-
}
5534+
return wrap(composer.apply(this));
55405535
}
55415536

5542-
55435537
/**
55445538
* Returns a new Observable that emits items resulting from applying a function that you supply to each item
55455539
* emitted by the source ObservableSource, where that function returns an ObservableSource, and then emitting the items

src/main/java/io/reactivex/ObservableTransformer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public interface ObservableTransformer<Upstream, Downstream> {
2525
* optionally different element type.
2626
* @param upstream the upstream Observable instance
2727
* @return the transformed ObservableSource instance
28-
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
29-
* into a RuntimeException
3028
*/
31-
ObservableSource<Downstream> apply(Observable<Upstream> upstream) throws Exception;
29+
ObservableSource<Downstream> apply(Observable<Upstream> upstream);
3230
}

src/main/java/io/reactivex/Single.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,12 +1473,7 @@ public final Single<T> hide() {
14731473
*/
14741474
@SchedulerSupport(SchedulerSupport.NONE)
14751475
public final <R> Single<R> compose(SingleTransformer<T, R> transformer) {
1476-
try {
1477-
return wrap(transformer.apply(this));
1478-
} catch (Throwable ex) {
1479-
Exceptions.throwIfFatal(ex);
1480-
throw ExceptionHelper.wrapOrThrow(ex);
1481-
}
1476+
return wrap(transformer.apply(this));
14821477
}
14831478

14841479
/**

src/main/java/io/reactivex/SingleTransformer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public interface SingleTransformer<Upstream, Downstream> {
2525
* optionally different element type.
2626
* @param upstream the upstream Single instance
2727
* @return the transformed SingleSource instance
28-
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
29-
* into a RuntimeException
3028
*/
31-
SingleSource<Downstream> apply(Single<Upstream> upstream) throws Exception;
29+
SingleSource<Downstream> apply(Single<Upstream> upstream);
3230
}

0 commit comments

Comments
 (0)