Aws-sdk-android: AWSMobileClient.getInstance().showSignIn() Crash in 2.12.1 upon submit: Can't create handler inside thread that has not called Looper.prepare()

Created on 25 Feb 2019  路  6Comments  路  Source: aws-amplify/aws-sdk-android

Describe the bug
I have an app running in 2.12.0. The app displays the SignInUI successfully and it works, signing in the user and also displaying errors when appropriate. After upgrade to 2.12.1, the app will now crash when the sign-in UI Sign In button is selected. No other code changed in the app. Reverting back to 2.12.0 resolves the problem.

The exception for use case, user does not provide any input an selects the Sign In button.

2019-02-25 00:43:15.025 2239-2293/com.buntingsoftware.modlist E/CognitoUserPoolsSignInProvider: Failed to login.
    com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException: Missing required parameter USERNAME (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: InvalidParameterException; Request ID: 3d005900-38c0-11e9-89c6-1da46b80413b)
        at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:730)
        at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
        at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.invoke(AmazonCognitoIdentityProviderClient.java:5953)
        at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.initiateAuth(AmazonCognitoIdentityProviderClient.java:4127)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$23.run(CognitoUser.java:2352)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$6$1.run(CognitoUser.java:782)
        at java.lang.Thread.run(Thread.java:761)


    --------- beginning of crash
2019-02-25 00:43:15.027 2239-2293/com.buntingsoftware.modlist E/AndroidRuntime: FATAL EXCEPTION: Thread-13
    Process: com.buntingsoftware.modlist, PID: 2239
    java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)
        at android.os.Handler.<init>(Handler.java:114)
        at android.app.Dialog.<init>(Dialog.java:151)
        at android.app.AlertDialog.<init>(AlertDialog.java:200)
        at android.app.AlertDialog$Builder.create(AlertDialog.java:1103)
        at android.app.AlertDialog$Builder.show(AlertDialog.java:1130)
        at com.amazonaws.mobile.auth.core.internal.util.ViewHelper.showDialog(ViewHelper.java:46)
        at com.amazonaws.mobile.auth.userpools.CognitoUserPoolsSignInProvider$4.onFailure(CognitoUserPoolsSignInProvider.java:363)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$23.run(CognitoUser.java:2381)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$6$1.run(CognitoUser.java:782)
        at java.lang.Thread.run(Thread.java:761)

To Reproduce
A code sample or steps:

initialize AWS then show the sign in as follows:

    private void showSignIn() {
        Log.d(TAG, "showSignIn()");

        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                AWSMobileClient.getInstance().showSignIn(
                        MainActivity.this,
                        SignInUIOptions.builder()
                                .nextActivity(MainActivity.class)
                                .logo(R.drawable.ic_modlist_aws_signin_icon)
                                .backgroundColor(Color.parseColor("#7FA7BC"))
                                .canCancel(false)
                                .build(),
                        new Callback<UserStateDetails>() {
                            @Override
                            public void onResult(UserStateDetails result) {
                                Log.d(TAG, "showSignIn() onResult() result: userState: " + result.getUserState());
                                switch (result.getUserState()) {
                                    case SIGNED_IN:
                                        Log.d(TAG, "showSignIn() callback: SIGNED_IN logged in!");
                                        initializeAndLoadData();
                                        break;
                                    case SIGNED_OUT:
                                        Log.d(TAG, "showSignIn() callback onResult: SIGNED_OUT ");
                                        initializeAWSMobileClient();
                                        break;
                                    case SIGNED_OUT_FEDERATED_TOKENS_INVALID:
                                        Log.d(TAG, "showSignIn() callback onResult: SIGNED_OUT_FEDERATED_TOKENS_INVALID");
                                        initializeAWSMobileClient();
                                        break;
                                    case SIGNED_OUT_USER_POOLS_TOKENS_INVALID:
                                        Log.d(TAG, "showSignIn() callback onResult: SIGNED_OUT_USER_POOLS_TOKENS_INVALID");
                                        initializeAWSMobileClient();
                                        break;
                                    case GUEST:
                                        Log.d(TAG, "showSignIn() callback onResult: GUEST");
                                        initializeAWSMobileClient();
                                        break;
                                    case UNKNOWN:
                                        Log.d(TAG, "showSignIn() callback onResult: UNKNOWN");
                                        initializeAWSMobileClient();
                                        break;
                                    default:
                                        Log.d(TAG, "showSignIn() callback onResult: default; Should not be possible.");
                                        initializeAWSMobileClient();
                                        break;
                                }
                            }

                            @Override
                            public void onError(Exception e) {
                                Log.e(TAG, "showSignIn().onError: ", e);
                            }
                        }
                );
            }});
    }
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.buntingsoftware.modlist"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 58
        versionName "1.16.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }

}

allprojects {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:gridlayout-v7:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:multidex:1.0.3'
//
//    implementation 'com.amazonaws:aws-android-sdk-core:2.12.0'
//    implementation 'com.amazonaws:aws-android-sdk-auth-core:2.12.0@aar'
//    implementation 'com.amazonaws:aws-android-sdk-pinpoint:2.12.0'
//    implementation 'com.amazonaws:aws-android-sdk-ddb:2.12.0'
//    implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.12.0'
//    implementation('com.amazonaws:aws-android-sdk-mobile-client:2.12.0@aar') { transitive = true }
//    implementation('com.amazonaws:aws-android-sdk-auth-userpools:2.12.0@aar') { transitive = true }
//
//    implementation('com.amazonaws:aws-android-sdk-auth-ui:2.12.0@aar') { transitive = true }
//    implementation('com.amazonaws:aws-android-sdk-auth-facebook:2.12.0@aar') { transitive = true }
//    implementation('com.amazonaws:aws-android-sdk-auth-google:2.12.0@aar') { transitive = true }
//    implementation('com.amazonaws:aws-android-sdk-apigateway-core:2.12.0') { transitive = true }
//    implementation('com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.12.0') {
//        transitive = true
//    }


    implementation 'com.amazonaws:aws-android-sdk-core:2.12.1'
    implementation 'com.amazonaws:aws-android-sdk-auth-core:2.12.1@aar'
    implementation 'com.amazonaws:aws-android-sdk-pinpoint:2.12.1'
    implementation 'com.amazonaws:aws-android-sdk-ddb:2.12.1'
    implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.12.1'
    implementation('com.amazonaws:aws-android-sdk-mobile-client:2.12.1@aar') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-auth-userpools:2.12.1@aar') { transitive = true }

    implementation('com.amazonaws:aws-android-sdk-auth-ui:2.12.1@aar') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-auth-facebook:2.12.1@aar') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-auth-google:2.12.1@aar') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-apigateway-core:2.12.1') { transitive = true }
    implementation('com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.12.1') {
        transitive = true
    }


    // Added per Pinpoint Push Notifications documentation:
    // https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-push-notifications.html
    implementation 'com.google.android.gms:play-services-auth:16.0+'
    implementation 'com.google.firebase:firebase-core:16.0.+'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

}

// Added per Pinpoint Push Notifications documentation:
// https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-push-notifications.html
apply plugin: 'com.google.gms.google-services'

Which AWS service(s) are affected?
Cognito User Pool sign in with AWSMobileClient.getInstance().showSignIn()

Environment Information (please complete the following information):

  • AWS Android SDK Version: 2.12.1
  • Device: Samsung SMJ72VPP (device) or Simulator Pixel 2
  • Android Version: 7.0 API 24 or 9.0 API 28
  • Specific to simulators: No

Additional context
The only change I made in my app was to change the AWS version to 2.12.1

AWSMobileClient Bug Needs Info from Requester

All 6 comments

Hi @BillBunting ,

We have a fix for this in an upcoming release, thank you for the detailed report.

@minbi I updated to 2.12.2 and have the same bug. When do you anticipate this will be fixed? I assume anyone using AWSMobileClient with AWSMobileClient.getInstance().showSignIn() is blocked from upgrading? The following exception is generated any time the user hits submit on the AWSMobileClient.getInstance().showSignIn() form for username/password sign-in. Even error validation generates the crash (in this case below, a invalid user name was submitted and no password was provided)

2019-03-04 20:55:11.851 21538-21625/com.buntingsoftware.modlist E/CognitoUserPoolsSignInProvider: Failed to login.
    com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException: User does not exist. (Service: AmazonCognitoIdentityProvider; Status Code: 400; Error Code: UserNotFoundException; Request ID: b61879b8-3ee9-11e9-9cd4-fb735d27e81e)
        at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:730)
        at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
        at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.invoke(AmazonCognitoIdentityProviderClient.java:5953)
        at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.initiateAuth(AmazonCognitoIdentityProviderClient.java:4127)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$23.run(CognitoUser.java:2352)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$6$1.run(CognitoUser.java:782)
        at java.lang.Thread.run(Thread.java:761)
2019-03-04 20:55:11.852 21538-21625/com.buntingsoftware.modlist E/AndroidRuntime: FATAL EXCEPTION: Thread-13
    Process: com.buntingsoftware.modlist, PID: 21538
    java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)
        at android.os.Handler.<init>(Handler.java:114)
        at android.app.Dialog.<init>(Dialog.java:151)
        at android.app.AlertDialog.<init>(AlertDialog.java:200)
        at android.app.AlertDialog$Builder.create(AlertDialog.java:1103)
        at android.app.AlertDialog$Builder.show(AlertDialog.java:1130)
        at com.amazonaws.mobile.auth.core.internal.util.ViewHelper.showDialog(ViewHelper.java:46)
        at com.amazonaws.mobile.auth.userpools.CognitoUserPoolsSignInProvider$4.onFailure(CognitoUserPoolsSignInProvider.java:363)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$23.run(CognitoUser.java:2381)
        at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$6$1.run(CognitoUser.java:782)
        at java.lang.Thread.run(Thread.java:761)

@BillBunting the last release was to support an infrastructure change. This issue was not addressed. This is still in my queue.

Hi @BillBunting ,

Please see if SDK release 2.12.5 fixes this issue for you.

You may see all changes in the changelog

@minbi I briefly tested and it seems to be resolved. I am now able to use the drop in UI. Thank you.

Resolved.

Was this page helpful?
0 / 5 - 0 ratings