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(android): use method-local ref to instance var for multi-thread safety #549 #550

Merged

Conversation

cristianoccazinsp
Copy link
Contributor

Make sure we use a final reference to the instance variables in case they are modified in another callback while being used.

Overview

Should fix: #549

The fix is rather simple, just keep a reference to the value before re-using it all around in the function so another callback changing the instance variables won't cause the null pointer exception nor inconsistencies with a value changed halfway through the call.

Test Plan

Tested on Google Pixel 5 (Android 12) and Pixel 2 (Android 11)

Make sure we use a final reference to the instance variables in case they are modified in another callback while being used.
Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

good solution for a classic multithreading issue, 👍

@mikehardy mikehardy changed the title Fix #549 fix(android): use method-local ref to instance var for multi-thread safety #549 Dec 9, 2021
@mikehardy mikehardy merged commit 81bbc87 into react-native-netinfo:master Dec 9, 2021
github-actions bot pushed a commit that referenced this pull request Dec 9, 2021
## [7.1.5](v7.1.4...v7.1.5) (2021-12-09)

### Bug Fixes

* **android:** use method-local ref to instance var for multi-thread safety [#549](#549) ([#550](#550)) ([81bbc87](81bbc87))
@matt-oakes
Copy link
Collaborator

🎉 This PR is included in version 7.1.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[7.1.4] Android null pointer exception
4 participants