Aws-sdk-android: NullPointerException Attempt to invoke virtual method 'java.lang.String com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType.getDestination()' on a null object reference

Created on 21 Oct 2019  路  12Comments  路  Source: aws-amplify/aws-sdk-android

Getting the following issue on SignUp result using the AWSMobileClient.
It always goes into onError() even after providing a valid username, email, password.
In AWS console the user is getting created and validated as well.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType.getDestination()' on a null object reference

To Reproduce
A code sample or steps:

fun signUpUser(userName: String, userEmail: String, password: String) {
        val attributes = HashMap<String, String>()
        attributes.put(AppConstants.ATTRIBUTE_NAME, userName)
        attributes.put(AppConstants.ATTRIBUTE_EMAIL, userEmail)
        AWSMobileClient.getInstance().signUp(userEmail, password, attributes, null, object :
            Callback<com.amazonaws.mobile.client.results.SignUpResult> {
            override fun onResult(signUpResult: com.amazonaws.mobile.client.results.SignUpResult?) {
                //signUp was Successful
                Log.d("TAG", "Sign up Success...isConfirmed" + signUpResult?.confirmationState)

                signUpResult?.let {
                    if (!it.confirmationState) {
                        Log.d(
                            "TAG", "Sign up Success...not Confirmed. verification code sent to:"
                                    + signUpResult.userCodeDeliveryDetails.destination
                        )
                        authResponseLiveData.postValue(SignUpResultStatus.VERIFICATION_REQUIRED)
                    } else {
                        Log.d("TAG", "Sign up Success...user Confirmed")
                        authResponseLiveData.postValue(SignUpResultStatus.SIGNED_UP_SUCCESSFULLY)
                    }
                }
            }

            override fun onError(exception: Exception?) {
                val errorMessage: String = if (exception is AmazonServiceException) {
                    Log.d("SignUp Failure", exception.errorMessage)
                    exception.errorMessage
                } else {
                    Log.d("SignUp Failure", "Something went wrong.")
                    "Something went wrong."
                }
                errorLiveData.postValue(Event(errorMessage))
            }
        })
}

Which AWS service(s) are affected?
AWSMobileClient SignUp()

Expected behavior
SignUp Result as success or failure

Environment Information (please complete the following information):

AWSMobileClient Bug

Most helpful comment

@kvasukib Thanks for the prompt reply, eagerly looking forward to the resolution of the issue. Thank you!

All 12 comments

@SubirZ Thank you for reporting to us. Sorry for the inconvenience caused.

Does this happen for every signUp operation?
Have you configured MFA in Cognito UserPools?
Can you describe the SignUp flow you have configured with Amazon Cognito?

@kvasukib Thanks for the reply. No, we haven't configured our user pool to have MFA or Verification enabled in our settings. The signup flow is as follows,

We have set email and name as required attributes for the user pool.
We are calling the signup method on AwsMobile client with required parameters (username, password) along with attributes.

When we are doing that, the user is successfully being created in the user pool. But the issue is, we aren't getting a successful response. It will trigger onError callback.

For more insight, this is exactly how our issue is https://forums.aws.amazon.com/thread.jspa?messageID=720943

Not to mention, when we use the same above described flow from IOS and WEB, we get a successful response. Any help on this would be appreciated. Thanks

@SubirZ Thank you for sharing the history of the old issue and the details. The issue has been addressed in the Cognito UserPools SDK (aws-android-sdk-cognitoidentityprovider), however the issue still exists in AWSMobileClient SDK (aws-android-sdk-mobile-client). I am working on a fix for the problem and in the process of testing it. I will update this issue with more details when the bug fix is released. Thank you!

@kvasukib Thanks for the prompt reply, eagerly looking forward to the resolution of the issue. Thank you!

PR #1272 will address this issue.

@kvasukib Is the release date planned for #1272 planned?

The fix has been released in 2.16.3 release. Please upgrade and let us know if the fix works.

Thanks! Will test it and update.

@kvasukib
aws_sdk_version = '2.16.3'
In our case we have disabled signup verification and the code on Android is below

AWSMobileClient.getInstance().signUp(lowerCaseLogin, pw, new HashMap<>(), validationData, new Callback<SignUpResult>() {
            @Override
            public void onResult(SignUpResult result) {
                Log.v(TAG,"SUCCESS : " + result.toString());
                AWSMobileClient.getInstance().signIn(lowerCaseLogin, pw, null, new Callback<SignInResult>() {
                    @Override
                    public void onResult(SignInResult result) {                       
                        onAuthSuccess();
                    }

                    @Override
                    public void onError(Exception e) {
                        loginError.setText(getString(R.string.createError));
                    }
                });
            }

            @Override
            public void onError(Exception e) {
                Log.v(TAG,"FAIL : " + e.toString());
                loginError.setText(getString(R.string.createUserExists));
            }
        });

The error is : java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.amazonaws.services.cognitoidentityprovider.model.CodeDeliveryDetailsType.getDestination()' on a null object reference.

Let me know if you need more info. Does this prevail for you @SubirZ

I am by passing the error on SignUp. But can you verify this on your your end @kvasukib . Has the usage changed since then? Thanks!

fun changePassword(existingPassword: String, newPassword: String) {

        getActivityContext()?.showLoader()

        AWSMobileClient.getInstance().changePassword(existingPassword, newPassword, object : Callback<Void> {

                override fun onResult(signInResult: Void?) {
                    ThreadUtils.runOnUiThread(Runnable {
                        getActivityContext()?.hideLoader()
                        getActivityContext()?.onBackPressed()
                    })
                }

                override fun onError(e: Exception) {
                    ThreadUtils.runOnUiThread(Runnable {
                        Log.d("errorAWS",e.toString())

                        login()

                    })
                }
            })
    }

Error

    java.lang.NullPointerException: Attempt to invoke virtual method 'com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool.getCurrentUser()' on a null object reference

Hi @UbaidKhan91 - that's a different error than the one being discussed here which may be caused by calling changePassword while being logged out (you need to be logged in to use that method). Could you please check that and if it's still a problem, create a new ticket?

@trivedishivang - Is your issue still happening in the latest version of the SDK?

Was this page helpful?
0 / 5 - 0 ratings