Error during SignIn - null object reference
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.
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?
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.
@mortphose @vincetran can be link to this? https://github.com/aws-amplify/aws-sdk-android/issues/3572
@lolucosmin doesn't look like any of the errors I've seen on my end, but can't rule out being related.
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 any progress on that?
@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.