Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: IllegalStateException: Disposable already set! #4448

Closed
amitshekhariitbhu opened this issue Aug 31, 2016 · 12 comments
Closed

2.x: IllegalStateException: Disposable already set! #4448

amitshekhariitbhu opened this issue Aug 31, 2016 · 12 comments
Labels
Milestone

Comments

@amitshekhariitbhu
Copy link

The below code gives the exception - (IllegalStateException: Disposable already set!):

Single.just("Amit")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SingleObserver<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onSuccess(String value) {
                    }

                    @Override
                    public void onError(Throwable e) {
                    }
                });

But when I remove subscribeOn and observeOn like below it works :

Single.just("Amit")
                .subscribe(new SingleObserver<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onSuccess(String value) {
                    }

                    @Override
                    public void onError(Throwable e) {
                    }
                });
@akarnokd akarnokd added the Bug label Aug 31, 2016
@akarnokd akarnokd added this to the 2.0 RC 2 milestone Aug 31, 2016
@akarnokd
Copy link
Member

Thanks for the feedback, there is a state management bugin Single.subscribeOn that causes this. I'll post a PR to fix this today; once merged, you may want to switch to the RxJava 2 snapshots to get this fix and dozen others since RC1.

@akarnokd
Copy link
Member

Fixed in #4450.

@bitsydarel
Copy link

Still getting the same error io.reactivex.exceptions.ProtocolViolationException: Disposable already set!

subscriptions.add(mWeatherObservableWithNetwork
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(mWeatherObserver));

when i remove the subscribeOn and ObserveOn, No exception

Using rxjava 2.0.6

@akarnokd
Copy link
Member

@bitsydarel Hi and thanks for using RxJava. In order to help you, could you clarify the following:

  • What is the type of mWeatherObservableWithNetwork?
  • Did you make sure the RxAndroid 2 doesn't force your project to use RxJava 2.0.1?
  • Could you provide the full stacktrace of the ProtocolViolationException? It may provide the hints where exactly the unwanted call happens from within RxJava.

@bitsydarel
Copy link

@akarnokd
mWeatherObservableWithNetwork = Single

from the github of RxAndroid they suggest to use 2.0.6 :
RxAndroid 2.0.1:
RxJava 2.0.6:

StackTrace :
02-28 18:51:12.241 19971-19971/com.darelbitsy.dbweather E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.darelbitsy.dbweather, PID: 19971
io.reactivex.exceptions.ProtocolViolationException: Disposable already set!
at io.reactivex.internal.disposables.DisposableHelper.reportDisposableSet(DisposableHelper.java:156)
at io.reactivex.internal.disposables.DisposableHelper.setOnce(DisposableHelper.java:82)
at io.reactivex.observers.DisposableSingleObserver.onSubscribe(DisposableSingleObserver.java:32)
at io.reactivex.internal.operators.single.SingleObserveOn$ObserveOnSingleObserver.onSubscribe(SingleObserveOn.java:57)
at io.reactivex.internal.operators.single.SingleSubscribeOn.subscribeActual(SingleSubscribeOn.java:35)
at io.reactivex.Single.subscribe(Single.java:2692)
at io.reactivex.internal.operators.single.SingleObserveOn.subscribeActual(SingleObserveOn.java:35)
at io.reactivex.Single.subscribe(Single.java:2692)
at io.reactivex.Single.subscribeWith(Single.java:2736)
at com.darelbitsy.dbweather.ui.CurrentWeatherFragment.lambda$-com_darelbitsy_dbweather_ui_CurrentWeatherFragment_lambda$1(CurrentWeatherFragment.java:257)
at com.darelbitsy.dbweather.ui.-$Lambda$0.$m$0(Unknown Source)
at com.darelbitsy.dbweather.ui.-$Lambda$0.onRefresh(Unknown Source)
at android.support.v4.widget.SwipeRefreshLayout$1.onAnimationEnd(SwipeRefreshLayout.java:189)
at android.support.v4.widget.CircleImageView.onAnimationEnd(CircleImageView.java:105)
at android.view.ViewGroup.finishAnimatingView(ViewGroup.java:6270)
at android.view.View.draw(View.java:16371)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.draw(View.java:16446)
at android.view.View.updateDisplayListIfDirty(View.java:15387)
at android.view.View.draw(View.java:16188)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.draw(View.java:16446)
at android.view.View.updateDisplayListIfDirty(View.java:15387)
at android.view.View.draw(View.java:16188)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.draw(View.java:16446)
at android.support.v4.view.ViewPager.draw(ViewPager.java:2443)
at android.view.View.updateDisplayListIfDirty(View.java:15387)
at android.view.View.draw(View.java:16188)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15379)
at android.view.View.draw(View.java:16188)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at android.view.View.updateDisplayListIfDirty(View.java:15379)
at android.view.View.draw(View.java:16188)
at android.view.ViewGroup.drawChild(ViewGroup.java:3735)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3525)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchDraw(PhoneWindow.java:2751)
at android.view.View.draw(View.java:16446)
at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2737)
at android.view.View.updateDisplayListIfDirty(View.java:15387)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:286)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:292)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:327)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3060)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2864)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2476)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1366)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6758)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:896)
at android.view.Choreographer.doCallbacks(Choreographer.java:698)
at android.view.Choreographer.doFrame(Choreographer.java:633)
at android.view.Choreographer$FrameDisplayEventRe

@akarnokd
Copy link
Member

Based on the stacktrace of io.reactivex.observers.DisposableSingleObserver.onSubscribe(DisposableSingleObserver.java:32) it seems you are reusing a DisposableSingleObserver, otherwise the failure would have been issued by Single.observeOn by itself. If not, please provide an example of your flow.

@bitsydarel
Copy link

That was it, thanks for the help too and for the work, really helping!

there was no mention of this behavior in the documentation right?

@akarnokd
Copy link
Member

It was not mentioned explicitly anywhere. I've created #5148 to track the progress on updating the documentation.

@xiaogu-space
Copy link

but I also met it like this
image

image

@akarnokd
Copy link
Member

The provided XObservers and XSubscribers are not reusable; you have to create a fresh one when subscribing to a source.

@xiaogu-space
Copy link

@akarnokd thanks

@akarnokd
Copy link
Member

The PR #5210 adds documentation about these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants