Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LoginEmailFragment NPE crash in onActivityResult() #413

Merged
merged 1 commit into from
Oct 15, 2018

Conversation

AmandaRiu
Copy link
Contributor

Fixes #408

The Issue

The crash is around the email address hint functionality on the email field for login. A NPE is thrown in the onActiivtyResult() method of the LoginEmailFragment. The mEmailInput variable is null and the code is attempting to call a method on this variable in onActivityResult():

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == EMAIL_CREDENTIALS_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
            mEmailInput.getEditText().setText(credential.getId());
            next(getCleanedEmail());
        } else {
            mHasDismissedEmailHints = true;
            mEmailInput.getEditText().postDelayed(new Runnable() { <------ CRASHES HERE -----|
                @Override
                public void run() {
                    if (isAdded()) {
                        ActivityUtils.showKeyboard(mEmailInput.getEditText());
                    }
                }
            }, getResources().getInteger(android.R.integer.config_mediumAnimTime));
        }

        mIsDisplayingEmailHints = false;
    }
}

mEmailInput gets initialized in the setupContent() method which is called during onCreateView() in the base Fragment class. So knowing this I'm assuming that somehow LoginEmailFragment's onActivityResult() is being called before onCreateView(). I've tried to replicate this crash by enabling "Don't keep activities" and trying to somehow hit that sweet spot where I activate the TextInput and then put the app in the background before the hint results are returned. No luck.

The Fix

Verify mEmailInput is not null before attempting to access it. There is no side effect of this fix since when setupContent() is finally called and mEmailInput is initialized, the email hint code will be called again.

@AmandaRiu AmandaRiu added the MVLP label Oct 12, 2018
@AmandaRiu AmandaRiu added this to the Public Beta - Sprint 2 milestone Oct 12, 2018
@AmandaRiu AmandaRiu added this to MVLP backlog in MVLP Kanban Board via automation Oct 12, 2018
@AmandaRiu AmandaRiu moved this from MVLP backlog to Review/Testing in MVLP Kanban Board Oct 12, 2018
@nbradbury nbradbury self-assigned this Oct 15, 2018
@nbradbury
Copy link
Contributor

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
MVLP Kanban Board
  
Shipped in 0.18
Development

Successfully merging this pull request may close these issues.

Fatal Exception: RuntimeException: Failure delivering result ResultInfo
2 participants