Fix NPE: use a getter for the current UserState#1590
Merged
Conversation
* The currentUserState could be null from a user's report * Replace currentUserState with getCurrentUserState() to avoid an NPE * Replaced more instances of currentUserState with getCurrentUserState() than just the cases reported by the user. Which are all the places in UserStateSynchronizer that access currentUserState and it could possibly be null.
jkasten2
requested changes
May 17, 2022
Member
jkasten2
left a comment
There was a problem hiding this comment.
Thinking we should change all currentUserState usages to getCurrentUserState() for consistency.
Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @nan-li)
* In the previous commit, we already replaced all access to `currentUserState` where it could possibly be `null`, with the getter `getCurrentUserState()`. * In this commit, replace all other access to `currentUserState` with the getter `getCurrentUserState()` for consistency purposes.
nan-li
commented
May 17, 2022
Contributor
Author
nan-li
left a comment
There was a problem hiding this comment.
Ok! Added another commit for this so that the first commit is to address the NPE specifically, and the second commit, for consistency.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @jkasten2)
jkasten2
approved these changes
May 17, 2022
Member
jkasten2
left a comment
There was a problem hiding this comment.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @nan-li)
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Use a getter for the
currentUserStateto avoid a null pointer exception.Details
Motivation
A customer reported 3 separate crashes for the app's users when (1) a device is logging out of email, or, (2) has logged out of email and is logging into a different email. The
currentUserStateis apparentlynull. To address these crash reports, replace currentUserState withgetCurrentUserState()to avoid these NPE's.I also replaced more instances of
currentUserStatewithgetCurrentUserState()than the 3 cases below reported by the user. These are other places in UserStateSynchronizer that access currentUserState and it could possibly be null.Crash 1: Not reproducible
The obfuscated method seems to be this line.
Crash 2: Not reproducible
Crash 3: Reproducible by the reporter, not reproducible on my end
Scope
In the places we were accessing
currentUserState, it should not be null anyway. Using a getter just ensures this, and creates it if it isnull.Testing
Unit testing
No new unit testing done.
Manual testing
Because I couldn't reproduce any of these exceptions, it was not testable.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is