Skip to content

NullPointerException in Socket.java #727

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mega-arbuz opened this issue Nov 3, 2022 · 3 comments
Closed

NullPointerException in Socket.java #727

mega-arbuz opened this issue Nov 3, 2022 · 3 comments
Labels
Milestone

Comments

@mega-arbuz
Copy link

mega-arbuz commented Nov 3, 2022

Describe the bug
Sometimes there is a crash when trying to connect while there is no connectivity (Android device in airplane mode)

To Reproduce

Please fill the following code example:
Line 232 in Socket.java

Socket.IO client version: 2.1.0

Java client

public void run() {
      // remove the ack from the map (to prevent an actual acknowledgement)
      acks.remove(ackId);

      // remove the packet from the buffer (if applicable)
      Iterator<Packet<JSONArray>> iterator = sendBuffer.iterator();
      while (iterator.hasNext()) {
          if (iterator.next().id == ackId) {
              iterator.remove();
          }
      }

      ackWithTimeout.onTimeout();
  }

The crash is happening when accessing iterator.next().id
It happened once on an obfuscated build, this is the stacktrace:

ava.lang.NullPointerException: Attempt to read from field 'int io.socket.parser.Packet.b' on a null object reference in method 'void io.socket.client.Socket$6$1.run()'
	at io.socket.client.Socket$6$1.run(SourceFile:4)
	at java.util.TimerThread.mainLoop(Timer.java:563)
	at java.util.TimerThread.run(Timer.java:513)

Expected behavior
Failed connection without crashing

Platform:

  • Device: Samsung A52
  • OS: Android 12

Additional context
Looks like one of the items in the iterator is null

@mega-arbuz mega-arbuz added the bug label Nov 3, 2022
@rmirabelle
Copy link

java.lang.NullPointerException · Attempt to read from field 'int io.socket.parser.Packet.id' on a null object reference
Socket.java:232 io.socket.client.Socket$6$1.runTimer.java:562 
java.util.TimerThread.mainLoopTimer.java:512 
java.util.TimerThread.run

Same I think. Unfortunately, the stack trace is so short, I can't determine the source.

This was referenced Jul 28, 2023
shahabrar7746 added a commit to shahabrar7746/socket.io-client-java that referenced this issue Dec 24, 2023
@Harshvardhan5488
Copy link

I am Working on an Android Project in Kotlin that uses this library for socket.
I am facing the same issue. Is there any fix for it?
This crash appears a lot many times.

Please provide any fix or update in the library.
Thanks

Here is the stack trace: (io.socket.client.Socket$6$1.run (Socket.java:232))
(Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'int io.socket.parser.Packet.id' on a null object reference in method 'void io.socket.client.Socket$6$1.run()')

at io.socket.client.Socket$6$1.run(Socket.java:232)
at java.util.TimerThread.mainLoop(Timer.java:563)
at java.util.TimerThread.run(Timer.java:513)

darrachequesne pushed a commit that referenced this issue Jul 10, 2024
Clearing the buffer upon timeout could lead to:

```
java.util.ConcurrentModificationException
	at java.base/java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:970)
	at java.base/java.util.LinkedList$ListItr.next(LinkedList.java:892)
	at io.socket.client.Socket$6$1.run(Socket.java:232)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)
```

Related:

- #710
- #727
- #758
- #759
@darrachequesne
Copy link
Member

This should be fixed by b00ae8e, included in version 2.1.1.

Please reopen if needed.

@darrachequesne darrachequesne added this to the 2.1.1 milestone Jul 11, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants