Skip to content

2.x: Remove checked exceptions from transformer interfaces. #4710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/main/java/io/reactivex/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -942,12 +942,7 @@ public final Throwable blockingGet(long timeout, TimeUnit unit) {
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final Completable compose(CompletableTransformer transformer) {
try {
return wrap(transformer.apply(this));
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
throw ExceptionHelper.wrapOrThrow(ex);
}
return wrap(transformer.apply(this));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/reactivex/CompletableTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public interface CompletableTransformer {
* Applies a function to the upstream Completable and returns a CompletableSource.
* @param upstream the upstream Completable instance
* @return the transformed CompletableSource instance
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
* into a RuntimeException
*/
CompletableSource apply(Completable upstream) throws Exception;
CompletableSource apply(Completable upstream);
}
7 changes: 1 addition & 6 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6322,12 +6322,7 @@ public final <U> Single<U> collectInto(final U initialItem, BiConsumer<? super U
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Flowable<R> compose(FlowableTransformer<T, R> composer) {
try {
return fromPublisher(composer.apply(this));
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
throw ExceptionHelper.wrapOrThrow(ex);
}
return fromPublisher(composer.apply(this));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/reactivex/FlowableTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public interface FlowableTransformer<Upstream, Downstream> {
* optionally different element type.
* @param upstream the upstream Flowable instance
* @return the transformed Publisher instance
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
* into a RuntimeException
*/
Publisher<Downstream> apply(Flowable<Upstream> upstream) throws Exception;
Publisher<Downstream> apply(Flowable<Upstream> upstream);
}
7 changes: 1 addition & 6 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2010,12 +2010,7 @@ public final <U> Maybe<U> cast(final Class<? extends U> clazz) {
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Maybe<R> compose(MaybeTransformer<T, R> transformer) {
try {
return wrap(transformer.apply(this));
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
throw ExceptionHelper.wrapOrThrow(ex);
}
return wrap(transformer.apply(this));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/reactivex/MaybeTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface MaybeTransformer<Upstream, Downstream> {
* optionally different element type.
* @param upstream the upstream Maybe instance
* @return the transformed MaybeSource instance
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
* into a RuntimeException
*/
MaybeSource<Downstream> apply(Maybe<Upstream> upstream) throws Exception;
MaybeSource<Downstream> apply(Maybe<Upstream> upstream);
}
8 changes: 1 addition & 7 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5530,15 +5530,9 @@ public final <U> Single<U> collectInto(final U initialValue, BiConsumer<? super
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Observable<R> compose(ObservableTransformer<T, R> composer) {
try {
return wrap(composer.apply(this));
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
throw ExceptionHelper.wrapOrThrow(ex);
}
return wrap(composer.apply(this));
}


/**
* Returns a new Observable that emits items resulting from applying a function that you supply to each item
* emitted by the source ObservableSource, where that function returns an ObservableSource, and then emitting the items
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/reactivex/ObservableTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface ObservableTransformer<Upstream, Downstream> {
* optionally different element type.
* @param upstream the upstream Observable instance
* @return the transformed ObservableSource instance
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
* into a RuntimeException
*/
ObservableSource<Downstream> apply(Observable<Upstream> upstream) throws Exception;
ObservableSource<Downstream> apply(Observable<Upstream> upstream);
}
7 changes: 1 addition & 6 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -1473,12 +1473,7 @@ public final Single<T> hide() {
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Single<R> compose(SingleTransformer<T, R> transformer) {
try {
return wrap(transformer.apply(this));
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
throw ExceptionHelper.wrapOrThrow(ex);
}
return wrap(transformer.apply(this));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/reactivex/SingleTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface SingleTransformer<Upstream, Downstream> {
* optionally different element type.
* @param upstream the upstream Single instance
* @return the transformed SingleSource instance
* @throws Exception in case the transformation throws, checked exceptions will be wrapped
* into a RuntimeException
*/
SingleSource<Downstream> apply(Single<Upstream> upstream) throws Exception;
SingleSource<Downstream> apply(Single<Upstream> upstream);
}
90 changes: 5 additions & 85 deletions src/test/java/io/reactivex/TransformerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void flowableTransformerThrows() {
try {
Flowable.just(1).compose(new FlowableTransformer<Integer, Integer>() {
@Override
public Publisher<Integer> apply(Flowable<Integer> v) throws Exception {
public Publisher<Integer> apply(Flowable<Integer> v) {
throw new TestException("Forced failure");
}
});
Expand All @@ -39,28 +39,12 @@ public Publisher<Integer> apply(Flowable<Integer> v) throws Exception {
}
}

@Test
public void flowableTransformerThrowsChecked() {
try {
Flowable.just(1).compose(new FlowableTransformer<Integer, Integer>() {
@Override
public Publisher<Integer> apply(Flowable<Integer> v) throws Exception {
throw new IOException("Forced failure");
}
});
fail("Should have thrown!");
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof IOException);
assertEquals("Forced failure", ex.getCause().getMessage());
}
}

@Test
public void observableTransformerThrows() {
try {
Observable.just(1).compose(new ObservableTransformer<Integer, Integer>() {
@Override
public Observable<Integer> apply(Observable<Integer> v) throws Exception {
public Observable<Integer> apply(Observable<Integer> v) {
throw new TestException("Forced failure");
}
});
Expand All @@ -70,28 +54,12 @@ public Observable<Integer> apply(Observable<Integer> v) throws Exception {
}
}

@Test
public void observableTransformerThrowsChecked() {
try {
Observable.just(1).compose(new ObservableTransformer<Integer, Integer>() {
@Override
public Observable<Integer> apply(Observable<Integer> v) throws Exception {
throw new IOException("Forced failure");
}
});
fail("Should have thrown!");
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof IOException);
assertEquals("Forced failure", ex.getCause().getMessage());
}
}

@Test
public void singleTransformerThrows() {
try {
Single.just(1).compose(new SingleTransformer<Integer, Integer>() {
@Override
public Single<Integer> apply(Single<Integer> v) throws Exception {
public Single<Integer> apply(Single<Integer> v) {
throw new TestException("Forced failure");
}
});
Expand All @@ -101,28 +69,12 @@ public Single<Integer> apply(Single<Integer> v) throws Exception {
}
}

@Test
public void singleTransformerThrowsChecked() {
try {
Single.just(1).compose(new SingleTransformer<Integer, Integer>() {
@Override
public Single<Integer> apply(Single<Integer> v) throws Exception {
throw new IOException("Forced failure");
}
});
fail("Should have thrown!");
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof IOException);
assertEquals("Forced failure", ex.getCause().getMessage());
}
}

@Test
public void maybeTransformerThrows() {
try {
Maybe.just(1).compose(new MaybeTransformer<Integer, Integer>() {
@Override
public Maybe<Integer> apply(Maybe<Integer> v) throws Exception {
public Maybe<Integer> apply(Maybe<Integer> v) {
throw new TestException("Forced failure");
}
});
Expand All @@ -132,28 +84,12 @@ public Maybe<Integer> apply(Maybe<Integer> v) throws Exception {
}
}

@Test
public void maybeTransformerThrowsChecked() {
try {
Maybe.just(1).compose(new MaybeTransformer<Integer, Integer>() {
@Override
public Maybe<Integer> apply(Maybe<Integer> v) throws Exception {
throw new IOException("Forced failure");
}
});
fail("Should have thrown!");
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof IOException);
assertEquals("Forced failure", ex.getCause().getMessage());
}
}

@Test
public void completabeTransformerThrows() {
try {
Completable.complete().compose(new CompletableTransformer() {
@Override
public Completable apply(Completable v) throws Exception {
public Completable apply(Completable v) {
throw new TestException("Forced failure");
}
});
Expand All @@ -162,20 +98,4 @@ public Completable apply(Completable v) throws Exception {
assertEquals("Forced failure", ex.getMessage());
}
}

@Test
public void completabeTransformerThrowsChecked() {
try {
Completable.complete().compose(new CompletableTransformer() {
@Override
public Completable apply(Completable v) throws Exception {
throw new IOException("Forced failure");
}
});
fail("Should have thrown!");
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof IOException);
assertEquals("Forced failure", ex.getCause().getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void compose() {
Single.just(1)
.compose(new SingleTransformer<Integer, Object>() {
@Override
public SingleSource<Object> apply(Single<Integer> f) throws Exception {
public SingleSource<Object> apply(Single<Integer> f) {
return f.map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/reactivex/maybe/MaybeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public void toNull() {
public void compose() {
Maybe.just(1).compose(new MaybeTransformer<Integer, Integer>() {
@Override
public MaybeSource<Integer> apply(Maybe<Integer> m) throws Exception {
public MaybeSource<Integer> apply(Maybe<Integer> m) {
return m.map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer w) throws Exception {
Expand Down