react-native-udp: Crash: Attempt to invoke virtual method 'void java.net.DatagramSocket.setReuseAddress(boolean)' on a null object reference
Description
App crashes if creating socket object is not successful (object equals to null). This issue is basically a copy of #119 as @Rapsssito asked to create a new one.
Error
com.tradle.react.UdpSocketClient.bind
UdpSocketClient.java, line 83
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.DatagramSocket.setReuseAddress(boolean)' on a null object reference
Stack traces
com.tradle.react.UdpSocketClient.bind UdpSocketClient.java:83
com.tradle.react.UdpSockets$2.run UdpSockets.java:118
java.lang.Thread.run Thread.java:919
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:1167
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java:641
java.lang.Thread.run Thread.java:919
Steps to reproduce
Probably, you need to create and close sockets on and on. It is really hard to reproduce quickly.
Current behavior
App crashes on some devices with multiple Android versions. Sometimes the error is Attempt to invoke virtual method 'void java.net.DatagramSocket.send(java.net.DatagramPacket)' on a null object reference
but the reason seems to be the same.
Expected behavior
App does not crash. The solution proposed by @rimzici is to surround the code responsible for crashing with a try/catch block (see the code in his fork: https://github.com/telldus/react-native-udp/blob/master/android/src/main/java/com/tradle/react/UdpSocketClient.java#L83-L91). However, maybe a better idea would be a simple null-checking?
Relevant information
react-native | 0.63.4 |
react-native-udp | 4.0.4 (but happens on earlier versions, too) |
Occurred on
Device | OS |
Galaxy S7 | Android 8 |
Galaxy S9 | Android 10 |
Galaxy S9+ | Android 10 |
Galaxy S10+ | Android 10 |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
@Rapsssito Thank you for your hard work. It seems that #144 has also been fixed.
Let give the fix a couple of days more. We currently have about 18 000 active users so so far about ~15% of them installed and run the app. As I said, I will inform you about any crashes.
Thanks!
@Rapsssito I hope you had a nice Christmas!
We released an app update a couple of days ago and it seems to be much better. Just one crash in the new implementation so far:
Error
Stack traces
Occurred on
Tested by about 2000 users. I will keep you updated if I have more crash reports.
@Rapsssito We do not plan to release any app update before Christmas or New Year’s Eve so it has to wait until the first week of January.
@Rapsssito Sure. We are going to release an update to our app on Monday, so we will need then a couple of days to see if there are any crash reports. Thanks!