aws-sdk-android icon indicating copy to clipboard operation
aws-sdk-android copied to clipboard

Error during SignIn - null object reference

Open mortphose opened this issue 1 year ago • 7 comments

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):

  • AWS Android SDK Version: 2.75.1
  • Device: Any device, but currently - Pixel 2XL, Xiaomi Redmi A2, Blackshark 4, etc.
  • Android Version: 11-13, but potentially all supported versions.
  • Specific to simulators: No

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

mortphose avatar Jul 10 '24 21:07 mortphose

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?

vincetran avatar Jul 12 '24 17:07 vincetran

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

mortphose avatar Jul 29 '24 15:07 mortphose

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

lolucosmin avatar Aug 08 '24 06:08 lolucosmin

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

mortphose avatar Aug 12 '24 14:08 mortphose

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.

tylerjroach avatar Aug 14 '24 17:08 tylerjroach

@tylerjroach any progress on that?

ghost avatar Oct 23 '24 12:10 ghost

@lgassense Unfortunately we haven't been able to carve out the time to come back into this yet but we'll be sure to update the issue once we do.

vincetran avatar Oct 23 '24 17:10 vincetran