-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.Socket.close()' on a null object reference #957
Comments
same situation, there may should be thread locked |
Hi @marci4
|
@pawankgupta-se looks like this issue is caused by the OS? |
@marci4 Not sure, but something related to Thread. But I have very simple code as of now. Not introducing any other thread from my side. And this issue is consistent. |
@pawankgupta-se there are a few other issues which you can find with a quick google e.g. square/okhttp#4260 |
I hava the same problem. There are two solutions for me.
`
` `
` |
This problem has broken down a lot,I hope the author can solve this problem in the next version。 |
Describe the bug
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.Socket.close()' on a null object reference
I have encountered this error many times, but I cannot reproduce it because I found that the error seems to be caused by multi-threaded concurrency.
I found that socket.close () appears in two different threads.
One is the reconnect() and it will call the reset():
One is in the WebsocketWriteThread:
Obviously the reconnect thread and the write thread are not the same thread.This reminds me of a piece of code I saw elsewhere.
It will have a null pointer error.It may take some time to run before the error occurs.After threadB just judged if (null! = mStr), it switched to threadA. At this time, threadA also judged that mStr was not null, so it set mStr to null, and then switched to threadB. When threadB gets the length A null pointer exception occurred.
So when reconnect () happens, is it possible that there are some conditions that triggered closeSocket in writeThread.And when reconnectThread sets the socket to null, just writeThread switches to socket.close().So it happened a null pointer exception and WebsocketWriteThread does not catch null pointer exception,it only catches IOException,so the entire application crashed.
Environment(please complete the following information):
The text was updated successfully, but these errors were encountered: