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

Stop pretending everyone implements view state right. #1202

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented Apr 22, 2024

Makes the two sites where we call View.restoreHierarchyState defensive, catching and logging thrown exceptions.

We normally prefer to let exceptions fly (https://en.wikipedia.org/wiki/Fail-fast_system), but View.onRestoreInstanceState is a particularly unforgiving method. Naive implementations throw if a view of one type attempts to restore state written by one of another type, which can happen if view ids are mismanaged. When these errors cause crashes in large apps, they are unlikely to be discovered before release and can be hellish to track down.

Crashing in such a case is an overreaction when the alternative, typically losing scroller positions or partially entered text values on rotation or when popping a back stack, is such a non-event.

Makes the two sites where we call `View.restoreHierarchyState` defensive, catching and logging thrown exceptions.

We normally prefer to let exceptions fly (https://en.wikipedia.org/wiki/Fail-fast_system), but `View.onRestoreInstanceState` is a particularly unforgiving method. Naive implementations throw if a view of one type attempts to restore state written by one of another type, which can happen if view ids are mismanaged. When these errors cause crashes in large apps, they are unlikely to be discovered before release and can be hellish to track down.

Crashing in such a case is an overreaction when the alternative, typically losing scroller positions or partially entered text values on rotation or when popping a back stack, is such a non-event.
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link

@pforhan pforhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rjrjr rjrjr merged commit cb05327 into main Apr 22, 2024
31 checks passed
@rjrjr rjrjr deleted the ray/view-state-is-trash branch April 22, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants