aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.02k stars 549 forks source link

Error during SignIn - null object reference #3608

Open mortphose opened 1 month ago

mortphose commented 1 month ago

Describe the bug When using signIn, I rarely receive this error:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobile.client.Callback.onError(java.lang.Exception)' on a null object reference
       at com.amazonaws.mobile.client.internal.InternalCallback.call(InternalCallback.java:77)
       at com.amazonaws.mobile.client.internal.InternalCallback.access$000(InternalCallback.java:34)
       at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:103)
       at java.lang.Thread.run(Thread.java:923)

To Reproduce Only way to reproduce it is using signIn, and even then, it's not every time.

Which AWS service(s) are affected? android-sdk-mobile-client and maybe android-sdk-auth-userpools

Expected behavior I don't expect this to happen with signIn.

Environment Information (please complete the following information):

Additional context I'm not able to replicate this reliably, so I'm not sure how common this is for users.

vincetran commented 1 month ago

Hi @mortphose, thanks for your report. Can you provide the code snippet of your sign in code to better understand how it's being called? And is that the full stacktrace?

mortphose commented 1 month ago

Apologies for the delay in my response, here's my sign in:

fun signIn(username: String?, password: String?) {
        AWSMobileClient.getInstance().signIn(username?.trim(), password?.trim(), null,
            object : Callback<SignInResult?> {
                override fun onResult(signInResult: SignInResult?) {
                    val signInState = signInResult?.signInState
                    when (signInState) {
                       <redacted>
                    }
                }

                override fun onError(e: Exception) {
                    <redacted>
                }
            }
        )
    }

It's a pretty basic call and function - I'm dealing with the data elsewhere after a login. I've also attached a firebase stacktrace.

firebase_aws_crash_stacktrace.txt

lolucosmin commented 3 weeks ago

@mortphose @vincetran can be link to this? https://github.com/aws-amplify/aws-sdk-android/issues/3572

mortphose commented 2 weeks ago

@lolucosmin doesn't look like any of the errors I've seen on my end, but can't rule out being related.

tylerjroach commented 2 weeks ago

I believe there may be a race condition here where onError is firing twice and the second time userCallback is null.

https://github.com/aws-amplify/aws-sdk-android/blob/6383576457d1106f0216c16119a5ec6c1bfaecb8/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/internal/InternalCallback.java#L88

The value gets set to Done and is not supposed to fire again, but if different threads try to provide a callback at the same time, a race condition may allow this null pointer.

We will look into fixing.