Skip to content

2.x: WithLatestFrom not calling onSubscribe() on actual observer #4969

Closed
@ZacSweers

Description

@ZacSweers

We're seeing an NPE from the s field of SerializedObserver not being set when used with .withLatestFrom(). Digging around in the source, it looks like it internally is not calling onSubscribe() to the actual observer field.

Example trace looks like this:

java.lang.NullPointerException
	at io.reactivex.observers.SerializedObserver.onNext(SerializedObserver.java:91)
	at io.reactivex.internal.operators.observable.ObservableWithLatestFrom$WithLatestFromObserver.onNext(ObservableWithLatestFrom.java:101)
	at io.reactivex.internal.operators.observable.ObservableFilter$FilterObserver.onNext(ObservableFilter.java:51)
	at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:63)
	at io.reactivex.subjects.PublishSubject$PublishDisposable.onNext(PublishSubject.java:263)
	at io.reactivex.subjects.PublishSubject.onNext(PublishSubject.java:182)

The snippet in SerializedObserver that corresponds to

    @Override
    public void onNext(T t) {
        if (done) {
            return;
        }
        if (t == null) {
            s.dispose();  // <----- this line, "s" is null because onSubscribe was never called
            onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
            return;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions