Skip to content

Rx Guideline 6.5: Subscribe implementations should not throw #278

Closed
@Treora

Description

@Treora

Some flavours of subscribe seem to ignore this guideline in the case that the given final Object onNext is null, for example: (Observable.java:366)

public Subscription subscribe(final Object onNext, final Object onError) {
    // lookup and memoize onNext
    if (onNext == null) {
        throw new RuntimeException("onNext must be implemented");
    }
    final FuncN onNextFunction = Functions.from(onNext);

This behaviour could be deliberately chosen, but then I wonder why other flavours of subscribe (those where an Action1<T> is passed) do neatly follow this guideline and only throw when onNext is actually being called: (Observable.java:428)

        public void onNext(T args) {
            if (onNext == null) {
                throw new RuntimeException("onNext must be implemented");
            }
            onNext.call(args);
        }

Moreover, I would actually expect both cases to call onError instead of throwing an Exception, though this could perhaps be defended, and for sure you would want to fix issue #198 first. It seems strange to me however that there is this difference in behaviour between passing an Object and passing an Action1 for onNext, or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions