FirebaseUI-Android icon indicating copy to clipboard operation
FirebaseUI-Android copied to clipboard

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' on a null object reference

Open rocketraman opened this issue 5 years ago • 5 comments

Step 2: Describe your environment

  • Android device: moto z4
  • Android OS version: 10
  • Google Play Services version: BOM 25.12.0
  • Firebase/Play Services SDK version: BOM 25.12.0
  • FirebaseUI version: 6.2.0

Step 3: Describe the problem:

Steps to reproduce:

  1. I don't know exactly. It happened shortly after calling the Firebase.signOut() method. Perhaps there is a timing issue with FirebaseUI not recognizing that the user has signed out.

Observed Results:

Crash with the following

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getEmail()' on a null object reference
	at com.firebase.ui.auth.util.CredentialUtils.buildCredential(CredentialUtils.java:33)
	at com.firebase.ui.auth.ui.HelperActivityBase.startSaveCredentials(HelperActivityBase.java:72)
	at com.firebase.ui.auth.ui.FragmentBase.startSaveCredentials(FragmentBase.java:36)
	at com.firebase.ui.auth.ui.email.RegisterEmailFragment$1.onSuccess(RegisterEmailFragment.java:103)
	at com.firebase.ui.auth.ui.email.RegisterEmailFragment$1.onSuccess(RegisterEmailFragment.java:100)
	at com.firebase.ui.auth.viewmodel.ResourceObserver.onChanged(ResourceObserver.java:69)
	at com.firebase.ui.auth.viewmodel.ResourceObserver.onChanged(ResourceObserver.java:19)
	at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
	at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
	at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
	at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
	at com.firebase.ui.auth.viewmodel.OperableViewModel.setResult(OperableViewModel.java:25)
	at com.firebase.ui.auth.viewmodel.SignInViewModelBase.setResult(SignInViewModelBase.java:23)
	at com.firebase.ui.auth.viewmodel.SignInViewModelBase.handleSuccess(SignInViewModelBase.java:27)
	at com.firebase.ui.auth.viewmodel.email.EmailProviderResponseHandler.access$700(EmailProviderResponseHandler.java:31)
	at com.firebase.ui.auth.viewmodel.email.EmailProviderResponseHandler$2.onSuccess(EmailProviderResponseHandler.java:60)
	at com.firebase.ui.auth.viewmodel.email.EmailProviderResponseHandler$2.onSuccess(EmailProviderResponseHandler.java:57)
	at com.google.android.gms.tasks.zzn.run(Unknown Source:4)
	at android.os.Handler.handleCallback(Handler.java:883)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:241)
	at android.app.ActivityThread.main(ActivityThread.java:7617)
	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:941)

Expected Results:

  • No crash

Relevant Code:

I don't have any specific way to reproduce this, and I'm not doing anything special with Firebase / FirebaseUI. The stack trace seems to be a background process that triggers on a network response, so that makes me think there is some kind of race condition in Firebase/FirebaseUI.

rocketraman avatar Dec 02 '20 16:12 rocketraman

@rocketraman thank you for the feedback. Have you tried upgrading to a more recent version of FirebaseUI? Given that you're using a somewhat old version (6.2.0) and you don't have steps to reproduce there's nothing I can really do to begin debugging this.

samtstern avatar Dec 03 '20 21:12 samtstern

Thanks, I haven't as I have dependencies that prevent me from upgrading at this time. I've only seen this happen once, so I'm fine with closing it. I can re-open or create a new issue if it happens to me again with a newer version of FirebaseUI.

rocketraman avatar Dec 03 '20 21:12 rocketraman

@rocketraman thanks for understanding, please let me know if you see this issue again.

samtstern avatar Dec 03 '20 22:12 samtstern

I'm re-opening this because I've seen it happen a few times now with FirebaseUI 8.0.2.

The exception is slightly different but its the same startSaveCredentials in the stack.

 java.lang.NullPointerException: Attempt to read from field 's5.G s5.e.b' on a null object reference in method 'com.google.android.gms.auth.api.credentials.Credential e7.a.r(r5.q, java.lang.String, java.lang.String)'
	at com.google.firebase.auth.internal.zzad.getEmail(com.google.firebase:firebase-auth@@23.1.0:49)
	at com.firebase.ui.auth.util.CredentialUtils.buildCredential(CredentialUtils.java:37)
	at com.firebase.ui.auth.ui.HelperActivityBase.startSaveCredentials(HelperActivityBase.java:81)
	at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity$1.onSuccess(AuthMethodPickerActivity.java:158)
	at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity$1.onSuccess(AuthMethodPickerActivity.java:155)
	at com.firebase.ui.auth.viewmodel.ResourceObserver.onChanged(ResourceObserver.java:69)
	at com.firebase.ui.auth.viewmodel.ResourceObserver.onChanged(ResourceObserver.java:19)
	at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
	at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
	at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
	at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
	at com.firebase.ui.auth.viewmodel.OperableViewModel.setResult(OperableViewModel.java:25)
	at com.firebase.ui.auth.viewmodel.SignInViewModelBase.setResult(SignInViewModelBase.java:23)
	at com.firebase.ui.auth.viewmodel.SignInViewModelBase.handleSuccess(SignInViewModelBase.java:27)
	at com.firebase.ui.auth.viewmodel.idp.SocialProviderResponseHandler.lambda$startSignIn$0(SocialProviderResponseHandler.java:74)
	at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.1.0:1)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8762)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

I believe it is a race condition with the signOut method in firebase-auth -- in this situation the user has validly signed in, but our application has seen that the user is invalid and calls the signOut method so that the user is able to sign in again with different credentials.

But firebase-ui is still completing the startSaveCredentials method after the firebase-auth signOut (note, not the firebase-ui signOut method) has already executed.

Android device: Galaxy S20 FE 5G (r8q) Android OS version: 13 Google Play Services version: BOM 33.6.0 Firebase/Play Services SDK version: BOM 33.6.0 FirebaseUI version: 8.0.2

rocketraman avatar Apr 15 '25 21:04 rocketraman

@rocketraman The latest version of FirebaseUI at the moment is 9.0.0 - can you please try upgrading to that version?

thatfiredev avatar Apr 16 '25 12:04 thatfiredev