Rxjava: CompositeDisposable holds reference from already disposed Disposable

Created on 24 Jan 2017  路  4Comments  路  Source: ReactiveX/RxJava

Thanks for using RxJava but before you post an issue, please consider the following points:

  • [x] Please include the library version number, including the minor and patch version, in the issue text. In addition, if you'd include the major version in the title (such as 2.x) that would be great.

-> compile 'io.reactivex.rxjava2:rxjava:2.0.3'

  • [x] If you think you found a bug, please include a code sample that reproduces the problem. Dumping a stacktrace is usually not enough for us.

-> This test is green.
Expected that disposable.size is 1. Like in CompositeSuubscription from RxJava 1.

    @Test
    public void name() throws Exception {
        final TestObserver<Integer> firstTestObserver = new TestObserver<>();
        firstTestObserver.dispose();
        final TestObserver<Integer> secondTestObserver = new TestObserver<>();

        assertThat(firstTestObserver.isDisposed(), is(equalTo(true)));
        assertThat(secondTestObserver.isDisposed(), is(equalTo(false)));

        final CompositeDisposable disposable = new CompositeDisposable();
        disposable.addAll(firstTestObserver, secondTestObserver);

        assertThat(disposable.size(), is(equalTo(2)));
    }
  • [x] RxJava has more than 150 operators, we recommend searching the javadoc for keywords of what you try to accomplish.

-> I expect that the CompositeDisposable don't add an already disposed Disposable.
Like the CompsositeSubscription.

2.x Question

All 4 comments

We don't do that anymore and the expected behavior is now deferred to the developer:

if (!firstTestObserver.isDisposed()) {
    disposable.add(firstTestObserver);
}

OK, when it is expected from your side it is ok for me 馃槃 鉂わ笍
Thanks for the fast response 馃憥

@akarnokd can you go into detail why it is beneficial to hold a reference to an already disposed Disposable?

Why would you try to add them in the first place if you know they are disposed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yubaokang picture yubaokang  路  3Comments

francorolando picture francorolando  路  3Comments

philleonard picture philleonard  路  3Comments

hoc081098 picture hoc081098  路  3Comments

archenroot picture archenroot  路  3Comments