18
18
import io .reactivex .*;
19
19
import io .reactivex .exceptions .*;
20
20
import io .reactivex .functions .Function ;
21
+ import io .reactivex .internal .functions .ObjectHelper ;
21
22
import io .reactivex .internal .subscriptions .SubscriptionArbiter ;
22
23
import io .reactivex .plugins .RxJavaPlugins ;
23
24
@@ -35,41 +36,47 @@ public FlowableOnErrorNext(Flowable<T> source,
35
36
@ Override
36
37
protected void subscribeActual (Subscriber <? super T > s ) {
37
38
OnErrorNextSubscriber <T > parent = new OnErrorNextSubscriber <T >(s , nextSupplier , allowFatal );
38
- s .onSubscribe (parent . arbiter );
39
+ s .onSubscribe (parent );
39
40
source .subscribe (parent );
40
41
}
41
42
42
- static final class OnErrorNextSubscriber <T > implements FlowableSubscriber <T > {
43
+ static final class OnErrorNextSubscriber <T >
44
+ extends SubscriptionArbiter
45
+ implements FlowableSubscriber <T > {
46
+ private static final long serialVersionUID = 4063763155303814625L ;
47
+
43
48
final Subscriber <? super T > actual ;
49
+
44
50
final Function <? super Throwable , ? extends Publisher <? extends T >> nextSupplier ;
51
+
45
52
final boolean allowFatal ;
46
- final SubscriptionArbiter arbiter ;
47
53
48
54
boolean once ;
49
55
50
56
boolean done ;
51
57
58
+ long produced ;
59
+
52
60
OnErrorNextSubscriber (Subscriber <? super T > actual , Function <? super Throwable , ? extends Publisher <? extends T >> nextSupplier , boolean allowFatal ) {
53
61
this .actual = actual ;
54
62
this .nextSupplier = nextSupplier ;
55
63
this .allowFatal = allowFatal ;
56
- this .arbiter = new SubscriptionArbiter ();
57
64
}
58
65
59
66
@ Override
60
67
public void onSubscribe (Subscription s ) {
61
- arbiter . setSubscription (s );
68
+ setSubscription (s );
62
69
}
63
70
64
71
@ Override
65
72
public void onNext (T t ) {
66
73
if (done ) {
67
74
return ;
68
75
}
69
- actual .onNext (t );
70
76
if (!once ) {
71
- arbiter . produced ( 1L ) ;
77
+ produced ++ ;
72
78
}
79
+ actual .onNext (t );
73
80
}
74
81
75
82
@ Override
@@ -92,18 +99,16 @@ public void onError(Throwable t) {
92
99
Publisher <? extends T > p ;
93
100
94
101
try {
95
- p = nextSupplier .apply (t );
102
+ p = ObjectHelper . requireNonNull ( nextSupplier .apply (t ), "The nextSupplier returned a null Publisher" );
96
103
} catch (Throwable e ) {
97
104
Exceptions .throwIfFatal (e );
98
105
actual .onError (new CompositeException (t , e ));
99
106
return ;
100
107
}
101
108
102
- if (p == null ) {
103
- NullPointerException npe = new NullPointerException ("Publisher is null" );
104
- npe .initCause (t );
105
- actual .onError (npe );
106
- return ;
109
+ long mainProduced = produced ;
110
+ if (mainProduced != 0L ) {
111
+ produced (mainProduced );
107
112
}
108
113
109
114
p .subscribe (this );
0 commit comments