Skip to content

2.x BiConsumer nullability annotations violated #5216

@davidschreiber

Description

@davidschreiber

RxJava 2.0.7

The BiConsumer interface has both parameters of its accept() method marked as @NonNull. However, when using the BiConsumer interface as result callback for a Single, the received parameter values are mutually exclusive being a non-null value and the other one being null. Although it seems to make sense in use, it violates the interface annotations and makes usage, at least, confusing.

Single.just("Some string")
    .subscribe(new BiConsumer<String, Throwable>() {
        @Override
        public void accept(@io.reactivex.annotations.NonNull String s, @io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
            assert s != null;
            assert throwable == null;
        }
    });

Single.<String>error(new RuntimeException())
    .subscribe(new BiConsumer<String, Throwable>() {
        @Override
        public void accept(@io.reactivex.annotations.NonNull String s, @io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
            assert s == null;
            assert throwable != null;
        }
    });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions