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

[SOLVED?] sample-mvi crashes on Start #314

Open
ValeriusGC opened this issue May 28, 2018 · 17 comments
Open

[SOLVED?] sample-mvi crashes on Start #314

ValeriusGC opened this issue May 28, 2018 · 17 comments

Comments

@ValeriusGC
Copy link

When i start it on Android Studio 3.1.2, app crashes with stack like this:

05-28 10:23:15.357 28499-28499/com.hannesdorfmann.mosby3.sample.mvi E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.hannesdorfmann.mosby3.sample.mvi, PID: 28499
    java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.
        at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:111)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.IllegalStateException: ViewState observable must not reach error state - onError()
        at com.hannesdorfmann.mosby3.mvi.DisposableViewStateObserver.onError(DisposableViewStateObserver.java:22)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated(ObservableObserveOn.java:276)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:172)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
        at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
        at android.os.Handler.handleCallback(Handler.java:751) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
     Caused by: java.lang.IllegalStateException: Only a single observer allowed.
        at io.reactivex.subjects.UnicastSubject.subscribeActual(UnicastSubject.java:150)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.subscribeInner(ObservableFlatMap.java:162)
        at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.onNext(ObservableFlatMap.java:139)
        at io.reactivex.internal.operators.observable.ObservableFromArray$FromArrayDisposable.run(ObservableFromArray.java:107)
        at io.reactivex.internal.operators.observable.ObservableFromArray.subscribeActual(ObservableFromArray.java:36)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableFlatMap.subscribeActual(ObservableFlatMap.java:55)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableConcatMap$ConcatMapDelayErrorObserver.drain(ObservableConcatMap.java:467)
        at io.reactivex.internal.operators.observable.ObservableConcatMap$ConcatMapDelayErrorObserver.onSubscribe(ObservableConcatMap.java:325)
        at io.reactivex.internal.operators.observable.ObservableFromArray.subscribeActual(ObservableFromArray.java:30)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableConcatMap.subscribeActual(ObservableConcatMap.java:54)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableCombineLatest$LatestCoordinator.subscribe(ObservableCombineLatest.java:119)
        at io.reactivex.internal.operators.observable.ObservableCombineLatest.subscribeActual(ObservableCombineLatest.java:73)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.internal.operators.observable.ObservableObserveOn.subscribeActual(ObservableObserveOn.java:45)
        at io.reactivex.Observable.subscribe(Observable.java:10700)
        at io.reactivex.Observable.subscribeWith(Observable.java:10751)
        at com.hannesdorfmann.mosby3.mvi.MviBasePresenter.subscribeViewState(MviBasePresenter.java:366)
        at com.hannesdorfmann.mosby3.sample.mvi.view.shoppingcartoverview.ShoppingCartOverviewPresenter.bindIntents(ShoppingCartOverviewPresenter.java:108)
        at com.hannesdorfmann.mosby3.mvi.MviBasePresenter.attachView(MviBasePresenter.java:248)
        at com.hannesdorfmann.mosby3.FragmentMviDelegateImpl.onStart(FragmentMviDelegateImpl.java:161)
        at com.hannesdorfmann.mosby3.mvi.MviFragment.onStart(MviFragment.java:91)
        at android.support.v4.app.Fragment.performStart(Fragment.java:2287)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1458)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3227)
        at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:3186)
        at android.support.v4.app.FragmentController.dispatchStart(FragmentController.java:203)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:582)
        at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248)
        at android.app.Activity.performStart(Activity.java:6696)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        	... 5 more
@ValeriusGC
Copy link
Author

Here is the change i made to fix this problem:
MviBasePresenter.java

        Subject<I> intentRelay = ReplaySubject.create();
        //Subject<I> intentRelay = UnicastSubject.create();

this was inserted on 513d1e9 ("use unicast subject", 2018-04-08)

@ValeriusGC ValeriusGC changed the title sample-mvi crashes on Start [SOLVED?] sample-mvi crashes on Start May 29, 2018
@sockeqwe
Copy link
Owner

sockeqwe commented Jul 3, 2018

Sorry for the long delay. I'm quite busy at the moment, I will take a look at this at the end of July.
As far as I can tell is that all automated tests (testing Mosby internals) are passing. Hence (without having investigated into this bug) I have the feeling that this is a Sample App issue.

@p8499
Copy link

p8499 commented Jan 9, 2019

When I upgrade mosby library from 3.1.0 to 3.1.1 I faced with this problem too.

@p8499
Copy link

p8499 commented Jan 9, 2019

Maybe UnicastSubject conflicts with the navigation feature,
stateObservable.share().map{...}.addTo(compositeDisposable)
thus makes it subscribed by two observables.

@drbear95
Copy link

Im facing this problem in my app, i tried with ReplaySubject but it doesn't work.

@sockeqwe
Copy link
Owner

sockeqwe commented Jun 1, 2019 via email

@drbear95
Copy link

drbear95 commented Jun 1, 2019

Here is my stack trace

 java.lang.IllegalStateException: ViewState observable must not reach error state - onError()
        at com.hannesdorfmann.mosby3.mvi.DisposableViewStateObserver.onError(DisposableViewStateObserver.java:22)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated(ObservableObserveOn.java:281)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:172)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:255)
        at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:119)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.IllegalStateException: Only a single observer allowed.
        at io.reactivex.subjects.UnicastSubject.subscribeActual(UnicastSubject.java:311)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableSwitchMap.subscribeActual(ObservableSwitchMap.java:51)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:32)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.subscribeInner(ObservableFlatMap.java:165)
        at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.onNext(ObservableFlatMap.java:139)
        at io.reactivex.internal.operators.observable.ObservableFromArray$FromArrayDisposable.run(ObservableFromArray.java:108)
        at io.reactivex.internal.operators.observable.ObservableFromArray.subscribeActual(ObservableFromArray.java:37)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableFlatMap.subscribeActual(ObservableFlatMap.java:55)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.subscribeInner(ObservableFlatMap.java:165)
        at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.onNext(ObservableFlatMap.java:139)
        at io.reactivex.internal.operators.observable.ObservableFromArray$FromArrayDisposable.run(ObservableFromArray.java:108)
        at io.reactivex.internal.operators.observable.ObservableFromArray.subscribeActual(ObservableFromArray.java:37)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableFlatMap.subscribeActual(ObservableFlatMap.java:55)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableScanSeed.subscribeActual(ObservableScanSeed.java:47)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
        at io.reactivex.Observable.subscribe(Observable.java:12090)
        at io.reactivex.internal.operators.observable.ObservableDistinctUntilChanged.subscribeActual(ObservableDistinctUntilChanged.java:35)
        at io.reactivex.Observable.subscribe(Observable.java:12090)

And here is my base presenter class

abstract class BasePresenter<TView : BaseView<TViewState>, TViewState: ViewState>(viewState: TViewState)
    : MviBasePresenter<TView, TViewState>(viewState) {

    protected val initialState: TViewState = viewState
    private var viewStateSnapshot: TViewState = viewState

    protected val lastViewState: TViewState
        get() = viewStateSnapshot

    override fun attachView(view: TView) {
        super.attachView(view)

        view.render(viewStateSnapshot)
    }


    override fun subscribeViewState(viewStateObservable: Observable<TViewState>, consumer: ViewStateConsumer<TView, TViewState>) {
        val viewStateStream = if(BuildConfig.DEBUG){
            viewStateObservable
        } else {
            viewStateObservable.map { it as ViewState }
                    .onErrorReturn {
                        FailureViewState()
                    }.filter { it !is FailureViewState }
                    .map { it as TViewState }
        }

        super.subscribeViewState(viewStateStream) { view, viewState ->
            this.viewStateSnapshot = viewState
            consumer.accept(view, viewState)
        }
    }

    private class FailureViewState: ViewState()
}

After changing Unicast to Relay (as ValeriusGC suggest) state is not beeing updated anymore.

@sockeqwe
Copy link
Owner

sockeqwe commented Jun 1, 2019 via email

@drbear95
Copy link

drbear95 commented Jun 3, 2019

When can I expect a fix? It is critical for my app because i cannot update to AndroidX

@sockeqwe
Copy link
Owner

sockeqwe commented Jun 5, 2019 via email

@drbear95
Copy link

What is the status of this case?

@michalmatusiak
Copy link

@sockeqwe any news? when it will be fixed?

@sockeqwe
Copy link
Owner

sockeqwe commented Jul 17, 2019 via email

@SunMaungOo
Copy link

@sockeqwe any update on the fix? I also got the same problem using AndroidX with version 3.1.1

@sockeqwe
Copy link
Owner

sockeqwe commented Sep 19, 2019 via email

@SunMaungOo
Copy link

@sockeqwe Just for your information , the solution provided by ValeriusGC which is changing it to ReplaySubject fix the problem. I don't know what effect it will have on other components but it fix the problem described.

@paul-wag
Copy link

Wish this had a solution.....

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

No branches or pull requests

7 participants