schibsted / account-sdk-android

⛔️ DEPRECATED Schibsted Account SDK for Android
https://schibsted.github.io/account-sdk-android/
MIT License
14 stars 8 forks source link

lateinit property primaryActionView has not been initialized #447

Open ziem opened 4 years ago

ziem commented 4 years ago

Summary

We sometimes see this issue when we launch Accound SDK login screen:

lateinit property primaryActionView has not been initialized

Environment

Details

Stacktrace:

kotlin.UninitializedPropertyAccessException: lateinit property primaryActionView has not been initialized at com.schibsted.account.ui.ui.FlowFragment.onVisibilityChanged(FlowFragment.kt:60) at com.schibsted.account.ui.login.BaseLoginActivity$onCreate$11.onChanged(BaseLoginActivity.kt:230) at com.schibsted.account.ui.login.BaseLoginActivity$onCreate$11.onChanged(BaseLoginActivity.kt:65) 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 com.schibsted.account.ui.KeyboardController$1.onGlobalLayout(KeyboardController.kt:50) at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1056) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2628) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966) at android.view.Choreographer.doCallbacks(Choreographer.java:790) at android.view.Choreographer.doFrame(Choreographer.java:725) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Code:

val accountUiParams = AccountUi.Params.Builder()
        .smartLockMode(SmartlockMode.ENABLED)
        .build()
val passwordActivityIntent = AccountUi.getCallingIntent(
        this,
        AccountUi.FlowType.PASSWORD,
        accountUiParams
)
startActivityForResult(passwordActivityIntent, REQUEST_LOGIN)

Steps to reproduce

Open login screen. The issue happens very rarely.

joakimcarlgren commented 3 years ago

This issue impacts Blocket a fair amount, small but not insignificant. Looking at the code this might be a race condition?

in BaseLoginActivity.onCreate() you call the fragment.onVisibilityChanged

        keyboardController.keyboardVisibility.observe(this, Observer {
            (navigationController.currentFragment as? FlowFragment<*>)?.onVisibilityChanged(it == true)
        })

But the properties in that fragment aren't resolved until the fragment.onViewCreated I am assuming that there is a theoretical chance here that the lifecycle of the fragment hasn't created the view yet.

If the root cause is hard to find / resolve could you maybe make sure not to access those properties if they've not been initialized? Or would that put the FlowFragment in an unknown state?