Skip to content

Commit 637978c

Browse files
authored
2.x: coverage, fixes, cleanup 10/15-1 (#4708)
* 2.x: coverage, fixes, cleanup 10/15-1 * Fix error message.
1 parent d250ae7 commit 637978c

26 files changed

+1615
-603
lines changed

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

+2-52
Original file line numberDiff line numberDiff line change
@@ -8305,7 +8305,7 @@ public final Observable<T> onTerminateDetach() {
83058305
*/
83068306
@SchedulerSupport(SchedulerSupport.NONE)
83078307
public final ConnectableObservable<T> publish() {
8308-
return publish(bufferSize());
8308+
return ObservablePublish.create(this);
83098309
}
83108310

83118311
/**
@@ -8329,58 +8329,8 @@ public final ConnectableObservable<T> publish() {
83298329
*/
83308330
@SchedulerSupport(SchedulerSupport.NONE)
83318331
public final <R> Observable<R> publish(Function<? super Observable<T>, ? extends ObservableSource<R>> selector) {
8332-
return publish(selector, bufferSize());
8333-
}
8334-
8335-
/**
8336-
* Returns an Observable that emits the results of invoking a specified selector on items emitted by a
8337-
* {@link ConnectableObservable} that shares a single subscription to the underlying sequence.
8338-
* <p>
8339-
* <img width="640" height="510" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/publishConnect.f.png" alt="">
8340-
* <dl>
8341-
* <dt><b>Scheduler:</b></dt>
8342-
* <dd>{@code publish} does not operate by default on a particular {@link Scheduler}.</dd>
8343-
* </dl>
8344-
*
8345-
* @param <R>
8346-
* the type of items emitted by the resulting ObservableSource
8347-
* @param selector
8348-
* a function that can use the multicasted source sequence as many times as needed, without
8349-
* causing multiple subscriptions to the source sequence. Observers to the given source will
8350-
* receive all notifications of the source from the time of the subscription forward.
8351-
* @param bufferSize
8352-
* the number of elements to prefetch from the current Observable
8353-
* @return an Observable that emits the results of invoking the selector on the items emitted by a {@link ConnectableObservable} that shares a single subscription to the underlying sequence
8354-
* @see <a href="http://reactivex.io/documentation/operators/publish.html">ReactiveX operators documentation: Publish</a>
8355-
*/
8356-
@SchedulerSupport(SchedulerSupport.NONE)
8357-
public final <R> Observable<R> publish(Function<? super Observable<T>, ? extends ObservableSource<R>> selector, int bufferSize) {
8358-
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
83598332
ObjectHelper.requireNonNull(selector, "selector is null");
8360-
return ObservablePublish.create(this, selector, bufferSize);
8361-
}
8362-
8363-
/**
8364-
* Returns a {@link ConnectableObservable}, which is a variety of ObservableSource that waits until its
8365-
* {@link ConnectableObservable#connect connect} method is called before it begins emitting items to those
8366-
* {@link Observer}s that have subscribed to it.
8367-
* <p>
8368-
* <img width="640" height="510" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/publishConnect.png" alt="">
8369-
* <dl>
8370-
* <dt><b>Scheduler:</b></dt>
8371-
* <dd>{@code publish} does not operate by default on a particular {@link Scheduler}.</dd>
8372-
* </dl>
8373-
*
8374-
* @param bufferSize
8375-
* the number of elements to prefetch from the current Observable
8376-
* @return a {@link ConnectableObservable} that upon connection causes the source ObservableSource to emit items
8377-
* to its {@link Observer}s
8378-
* @see <a href="http://reactivex.io/documentation/operators/publish.html">ReactiveX operators documentation: Publish</a>
8379-
*/
8380-
@SchedulerSupport(SchedulerSupport.NONE)
8381-
public final ConnectableObservable<T> publish(int bufferSize) {
8382-
ObjectHelper.verifyPositive(bufferSize, "bufferSize");
8383-
return ObservablePublish.create(this, bufferSize);
8333+
return new ObservablePublishSelector<T, R>(this, selector);
83848334
}
83858335

83868336
/**

src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java

+8-17
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,15 @@ public boolean isDisposed() {
106106
@Override
107107
public void onNext(T t) {
108108
U b = buffer;
109-
if (b == null) {
110-
return;
111-
}
112-
113-
b.add(t);
109+
if (b != null) {
110+
b.add(t);
114111

115-
if (++size >= count) {
116-
actual.onNext(b);
112+
if (++size >= count) {
113+
actual.onNext(b);
117114

118-
size = 0;
119-
createBuffer();
115+
size = 0;
116+
createBuffer();
117+
}
120118
}
121119
}
122120

@@ -185,21 +183,14 @@ public void onNext(T t) {
185183
U b;
186184

187185
try {
188-
b = bufferSupplier.call();
186+
b = ObjectHelper.requireNonNull(bufferSupplier.call(), "The bufferSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
189187
} catch (Throwable e) {
190188
buffers.clear();
191189
s.dispose();
192190
actual.onError(e);
193191
return;
194192
}
195193

196-
if (b == null) {
197-
buffers.clear();
198-
s.dispose();
199-
actual.onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
200-
return;
201-
}
202-
203194
buffers.offer(b);
204195
}
205196

src/main/java/io/reactivex/internal/operators/observable/ObservableConcatMapEager.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,8 @@ void disposeAll() {
183183

184184
for (;;) {
185185

186-
try {
187-
inner = observers.poll();
188-
} catch (Throwable ex) {
189-
Exceptions.throwIfFatal(ex);
190-
throw ExceptionHelper.wrapOrThrow(ex);
191-
}
186+
inner = observers.poll();
187+
192188
if (inner == null) {
193189
return;
194190
}

0 commit comments

Comments
 (0)