fix: 🐛 #188 (android): Add null checks to prevent NullPointerException…#227
Merged
Rapsssito merged 1 commit intoRapsssito:masterfrom Jan 1, 2026
Merged
fix: 🐛 #188 (android): Add null checks to prevent NullPointerException…#227Rapsssito merged 1 commit intoRapsssito:masterfrom
Rapsssito merged 1 commit intoRapsssito:masterfrom
Conversation
Contributor
Author
|
Currently testing these changes. |
Contributor
Author
|
Tested and ready for review. Happy new year! @Rapsssito |
Contributor
Author
|
@Rapsssito the semantic release of this PR failed. Something about your NPM credentials. |
Owner
|
@louiscavalcante, Wops! My bad. NPM just removed classic tokens. I will create a new one ASAP. |
github-actions bot
pushed a commit
that referenced
this pull request
Jan 3, 2026
## [6.3.1](v6.3.0...v6.3.1) (2026-01-03) ### Bug Fixes * **Android:** prevent NullPointerException in TcpReceiverTask ([#227](#227)) ([27203eb](27203eb))
|
🎉 This PR is included in version 6.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
This PR closes Issue #188
Problem
The app crashes with a
NullPointerExceptionwhen the socket becomes null during receiver task operations:Root Cause Analysis
This is a race condition in
TcpReceiverTask.run(). The socket can become null between retrieval and usage due to:destroy()called concurrently: Ifdestroy()is called while the receiver task is starting or running, it setssocket = null(line 190) while the receiver thread may be accessing it.Timing window: The receiver task runs in a separate thread (
listenExecutor). There's a window between whengetSocket()returns and whensocket.getInputStream()is called where another thread can calldestroy().No synchronization: The
socketfield is accessed from multiple threads without synchronization:connect(),destroy(),startTLS()TcpReceiverTask.run()write()Triggering Scenario
In my case, this occurred when using
react-native-zeroconffor mDNS service discovery followed by immediate TCP connection:Changes
1. Add null guard at start of
TcpReceiverTask.run()2. Add null check in catch block
The catch block also accessed
socket.isClosed()without null checking:3. Add null checks in
pause()andresume()methodsThese methods access
receiverTaskwithout null checking. If called beforestartListening()completes, they would throw NPE:Why This Fix
This is a defensive fix that prevents the crash without changing the library's behavior. The alternative would be to add proper thread synchronization (synchronized blocks or locks), but that would be a more invasive change with potential performance implications.
The
write()method already has this pattern (lines 157-159):This PR applies the same defensive pattern to the receiver task.
Testing
Tested by:
NullPointerExceptionoccursImpact