TWiStErRob / net.twisterrob.libraries

1 stars 0 forks source link

Invalid DynamicLoaderManager state on rotation #33

Open TWiStErRob opened 1 year ago

TWiStErRob commented 1 year ago

Repro:

11:28:43.477  3983-3983  AndroidRuntime          net.twisterrob.inventory.debug                 E  FATAL EXCEPTION: main
Process: net.twisterrob.inventory.debug, PID: 3983
java.lang.AssertionError
    at net.twisterrob.android.content.loader.DynamicLoaderManager.onLoadFinished(DynamicLoaderManager.java:57)
    at androidx.loader.app.LoaderManagerImpl$LoaderObserver.onChanged(LoaderManagerImpl.java:254)
    at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
    at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
    at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
    at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.setValue(LoaderManagerImpl.java:188)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManagerImpl.java:173)
    at androidx.loader.content.Loader.deliverResult(Loader.java:131)
    at net.twisterrob.android.content.loader.AsyncLoader.deliverResult(AsyncLoader.java:41)
    at net.twisterrob.inventory.android.content.Loaders$LoadersCursorLoader.deliverResult(Loaders.java:262)
    at net.twisterrob.inventory.android.content.Loaders$LoadersCursorLoader.deliverResult(Loaders.java:231)
    at net.twisterrob.android.content.loader.AsyncLoader.onStartLoading(AsyncLoader.java:60)
    at androidx.loader.content.Loader.startLoading(Loader.java:284)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.onActive(LoaderManagerImpl.java:76)
    at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:437)
    at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:395)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
    at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:188)
    at androidx.lifecycle.LiveData.observe(LiveData.java:203)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.setCallback(LoaderManagerImpl.java:99)
    at androidx.loader.app.LoaderManagerImpl.initLoader(LoaderManagerImpl.java:429)
    at net.twisterrob.android.content.loader.DynamicLoaderManager.start(DynamicLoaderManager.java:83)
    at net.twisterrob.android.content.loader.DynamicLoaderManager.onLoadFinished(DynamicLoaderManager.java:75)
    at androidx.loader.app.LoaderManagerImpl$LoaderObserver.onChanged(LoaderManagerImpl.java:254)
    at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
    at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
    at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
    at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.setValue(LoaderManagerImpl.java:188)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManagerImpl.java:173)
    at androidx.loader.content.Loader.deliverResult(Loader.java:131)
    at net.twisterrob.android.content.loader.AsyncLoader.deliverResult(AsyncLoader.java:41)
    at net.twisterrob.inventory.android.content.Loaders$LoadersCursorLoader.deliverResult(Loaders.java:262)
    at net.twisterrob.inventory.android.content.Loaders$LoadersCursorLoader.deliverResult(Loaders.java:231)
    at net.twisterrob.android.content.loader.AsyncLoader.onStartLoading(AsyncLoader.java:60)
    at androidx.loader.content.Loader.startLoading(Loader.java:284)
    at androidx.loader.app.LoaderManagerImpl$LoaderInfo.onActive(LoaderManagerImpl.java:76)
    at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:437)
    at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:395)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
    at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
    at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
    at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
    at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
    at androidx.fragment.app.Fragment.performStart(Fragment.java:2736)
    at androidx.fragment.app.FragmentStateManager.start(FragmentStateManager
TWiStErRob commented 1 year ago

Sanitized logs for comparing behavior: last commit on 33.txt 11303191-v1.1.3#3191.txt

this didn't reveal much, the problem is that the delivery happens synchronously, start() gets called which would assign state.loader, but onLoadFinished gets called before that assignment could happen: image

this is the problematic behavior: image

TWiStErRob commented 1 year ago

Oh, it's the same in the old version too, it just doesn't have assertions enabled image

Old sources: z:\caches\gradle\caches\modules-2\files-2.1\com.android.support\support-v4\24.1.1\1011f8c906a5f8f53eef8fd669fc3c2afebe04f7\support-v4-24.1.1-sources.jar

TWiStErRob commented 1 year ago

The state.loader == null part of the assertion is just hiding this issue, need to find another way.