Skip to content

Fix NPE when removing view reference #678

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

Merged
merged 1 commit into from
Jul 28, 2022
Merged

Fix NPE when removing view reference #678

merged 1 commit into from
Jul 28, 2022

Conversation

MarioNoll
Copy link
Contributor

After upgrading from 3.1.5 to 3.1.6, we can see users running into a NPE, introduced here.

@EricKuck EricKuck merged commit ac4e09c into bluelinelabs:develop Jul 28, 2022
@@ -1082,7 +1082,7 @@ private void removeViewReference(@Nullable Context context) {
final View inflate(@NonNull ViewGroup parent) {
if (view != null && view.getParent() != null && view.getParent() != parent) {
detach(view, true, false);
removeViewReference(view.getContext());
removeViewReference(view != null ? view.getContext() : null);
Copy link
Collaborator

@PaulWoitaschek PaulWoitaschek Jul 28, 2022

Choose a reason for hiding this comment

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

Wouldn't a more correct behavior be, to capture the view locally in the beginning of the method body?

Copy link
Member

Choose a reason for hiding this comment

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

This is a good call. Doesn't matter in this case because the context is only used when the controller is being destroyed and it will never be getting destroyed during inflate. But for the sake of correctness and avoiding future footguns I'll update it to work this way.

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.

3 participants