Skip to content

Commit 3aad9a6

Browse files
authored
1.x: Fix take() to route late errors to RxJavaHooks (#5935)
1 parent 0641802 commit 3aad9a6

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/main/java/rx/internal/operators/OperatorTake.java

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import rx.*;
2121
import rx.Observable.Operator;
22+
import rx.plugins.RxJavaHooks;
2223

2324
/**
2425
* An {@code Observable} that emits the first {@code num} items emitted by the source {@code Observable}.
@@ -66,6 +67,8 @@ public void onError(Throwable e) {
6667
} finally {
6768
unsubscribe();
6869
}
70+
} else {
71+
RxJavaHooks.onError(e);
6972
}
7073
}
7174

src/test/java/rx/internal/operators/OperatorTakeTest.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919
import static org.mockito.Matchers.*;
2020
import static org.mockito.Mockito.*;
2121

22-
import java.util.Arrays;
22+
import java.util.*;
2323
import java.util.concurrent.*;
2424
import java.util.concurrent.atomic.*;
2525

2626
import org.junit.Test;
2727
import org.mockito.InOrder;
2828

2929
import rx.*;
30+
import rx.Observable;
3031
import rx.Observable.OnSubscribe;
32+
import rx.Observer;
3133
import rx.exceptions.TestException;
3234
import rx.functions.*;
3335
import rx.observers.*;
36+
import rx.plugins.RxJavaHooks;
3437
import rx.schedulers.Schedulers;
3538
import rx.subjects.PublishSubject;
3639

@@ -457,4 +460,39 @@ public void takeZero() {
457460
ts.assertCompleted();
458461
}
459462

463+
@Test
464+
public void crashReportedToHooks() {
465+
final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>());
466+
RxJavaHooks.setOnError(new Action1<Throwable>() {
467+
@Override
468+
public void call(Throwable error) {
469+
errors.add(error);
470+
}
471+
});
472+
473+
try {
474+
Observable.just("1")
475+
.take(1)
476+
.toSingle()
477+
.subscribe(
478+
new Action1<String>() {
479+
@Override
480+
public void call(String it) {
481+
throw new TestException("bla");
482+
}
483+
},
484+
new Action1<Throwable>() {
485+
@Override
486+
public void call(Throwable error) {
487+
errors.add(new AssertionError());
488+
}
489+
}
490+
);
491+
492+
assertEquals("" + errors, 1, errors.size());
493+
assertTrue("" + errors.get(0), errors.get(0).getMessage().equals("bla"));
494+
} finally {
495+
RxJavaHooks.setOnError(null);
496+
}
497+
}
460498
}

0 commit comments

Comments
 (0)