Skip to content
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
19 changes: 17 additions & 2 deletions src/main/java/rx/observables/SyncOnSubscribe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import rx.Subscriber;
import rx.Subscription;
import rx.annotations.Experimental;
import rx.exceptions.Exceptions;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Action2;
Expand Down Expand Up @@ -53,7 +54,16 @@ public abstract class SyncOnSubscribe<S, T> implements OnSubscribe<T> {
*/
@Override
public final void call(final Subscriber<? super T> subscriber) {
S state = generateState();
S state;

try {
state = generateState();
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
subscriber.onError(e);
return;
}

SubscriptionProducer<S, T> p = new SubscriptionProducer<S, T>(subscriber, this, state);
subscriber.add(p);
subscriber.setProducer(p);
Expand Down Expand Up @@ -363,7 +373,12 @@ private boolean tryUnsubscribe() {
}

private void doUnsubscribe() {
parent.onUnsubscribe(state);
try {
parent.onUnsubscribe(state);
} catch (Throwable e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test that too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, this exception has nowhere to go and hijacking the plugins is a nightmare.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sad, would be nice to have a way to test such cases.

On Tue, 26 Jan 2016, 00:44 David Karnok [email protected] wrote:

In src/main/java/rx/observables/SyncOnSubscribe.java
#3644 (comment):

@@ -363,7 +373,12 @@ private boolean tryUnsubscribe() {
}

     private void doUnsubscribe() {
  •        parent.onUnsubscribe(state);
    
  •        try {
    
  •            parent.onUnsubscribe(state);
    
  •        } catch (Throwable e) {
    

Not really, this exception has nowhere to go and hijacking the plugins is
a nightmare.


Reply to this email directly or view it on GitHub
https://github.com/ReactiveX/RxJava/pull/3644/files#r50760936.

@artem_zin

Exceptions.throwIfFatal(e);
RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
}
}

@Override
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/rx/observables/SyncOnSubscribeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -989,4 +989,27 @@ public Object call() throws Exception {
if (exec != null) exec.shutdownNow();
}
}

@Test
public void testStateThrows() {
TestSubscriber<Object> ts = new TestSubscriber<Object>();

SyncOnSubscribe.<Object, Object>createSingleState(
new Func0<Object>() {
@Override
public Object call() {
throw new TestException();
}
}
, new Action2<Object, Observer<Object>>() {
@Override
public void call(Object s, Observer<? super Object> o) {

}
}).call(ts);

ts.assertNoValues();
ts.assertError(TestException.class);
ts.assertNotCompleted();
}
}