google / ground-android

Ground mobile data collection app for Android
http://groundplatform.org
Apache License 2.0
245 stars 119 forks source link

[App Crash] activeSurvey is null #2815

Open anandwana001 opened 2 weeks ago

anandwana001 commented 2 weeks ago
 Fatal Exception: java.lang.IllegalArgumentException: Required value was null.
       at com.google.android.ground.ui.datacollection.DataCollectionViewModel.<init>(DataCollectionViewModel.kt:100)
       at com.google.android.ground.DaggerGroundApplication_HiltComponents_SingletonC$ViewModelCImpl$SwitchingProvider.get(DaggerGroundApplication_HiltComponents_SingletonC.java:1465)
       at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$2.createViewModel(HiltViewModelFactory.java:132)
       at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$2.create(HiltViewModelFactory.java:103)
       at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:170)
       at androidx.lifecycle.ViewModelProvider$Factory.create(ViewModelProvider.android.kt:158)
       at androidx.lifecycle.viewmodel.ViewModelProviderImpl_androidKt.createViewModel(ViewModelProviderImpl.android.kt:34)
       at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release(ViewModelProviderImpl.kt:65)
       at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release$default(ViewModelProviderImpl.kt:47)
       at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:91)
       at androidx.lifecycle.ViewModelLazy.getValue(ViewModelLazy.kt:51)
       at androidx.lifecycle.ViewModelLazy.getValue(ViewModelLazy.kt:35)
       at com.google.android.ground.ui.datacollection.DataCollectionFragment.getViewModel(DataCollectionFragment.kt:55)
       at com.google.android.ground.ui.datacollection.DataCollectionFragment.onViewCreated(DataCollectionFragment.kt:86)
       at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3152)
       at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:608)
       at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286)
       at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:114)
       at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1675)
       at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3259)
       at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:3170)
       at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3153)
       at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:608)
       at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286)
       at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:114)
       at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1675)
       at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3259)
       at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3177)
       at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:263)
       at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:350)
       at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
       at com.google.android.ground.AbstractActivity.onStart(AbstractActivity.kt:53)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1455)
       at android.app.Activity.performStart(Activity.java:8105)
       at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3745)
       at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:222)
       at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:202)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:174)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:98)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7996)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:553)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
gino-m commented 1 week ago

This crash occurerd 20 times in the last 30 days, all from DataCollectionViewModel, but with no crash keys set. This implies that the crash occurred outside of the normal app lifecycle, perhaps after a draft was restored after the app was killed. Filing as P1.

gino-m commented 2 days ago

The crash occurs here:

  private val activeSurvey: Survey = requireNotNull(surveyRepository.activeSurvey)

This sounds like a race condition because we're using a synchronous call to activeSurvey, which may not have been initialized yet when the view is being restored. Likely happening after the app is killed and restarted during data collection.