[Reader] Fix UninitializedPropertyAccessException in ReaderFragment #20143
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.
Fixes #20142
To Test:
I couldn't reproduce this crash. The
ViewModel
is initialized whenReaderFragment#onViewCreated
is called. The crash log tells us thatReaderFragment#onSaveInstanceState
was called beforeReaderFragment#onViewCreated
, sinceViewModel
was not initialized.There wasn't a single time where I was able to make
onSaveInstanceState
be called beforeonViewCreated
:onSaveInstanceState
is called afteronStop
in recent versions and might be called before or after (no guarantees on order)onPause
in older versions. This means for this crash to happen, theActivity
should've been stopped beforeonViewCreated
is called.For now I've added a check to see if the
ViewModel
property was initialized before using it to avoid the crash.Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
--
PR Submission Checklist:
RELEASE-NOTES.txt
if necessary.Testing Checklist: