resourcepool / ssdp-client

The most lightweight asynchronous Java SSDP (Simple Service Discovery Protocol) Client
Apache License 2.0
53 stars 21 forks source link

NullPointerException io.resourcepool.ssdp.client.impl.SsdpClientImpl in handlePresenceAnnouncement #35

Closed micheleb closed 1 year ago

micheleb commented 1 year ago

Hi! 👋🏻 We've seen some crashes in our app (we're using this library on Android) due to this error:

java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
    at io.resourcepool.ssdp.client.impl.SsdpClientImpl.handlePresenceAnnouncement(SsdpClientImpl.java:227)
    at io.resourcepool.ssdp.client.impl.SsdpClientImpl.handleIncomingPacket(SsdpClientImpl.java:154)
    at io.resourcepool.ssdp.client.impl.SsdpClientImpl.access$300(SsdpClientImpl.java:34)
    at io.resourcepool.ssdp.client.impl.SsdpClientImpl$3.run(SsdpClientImpl.java:122)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:784)

It looks like handlePresenceAnnouncement is sometimes called before reset() is invoked, thus incurring in the NPE above.

I've added this small workaround to avoid getting NPEs, but of course it doesn't actually solve the problem (maybe these announcements could be saved to a temporary list waiting for a scan request to come?).

loicortola commented 1 year ago

Hi @micheleb ,

thanks for the commit, I would appreciate a PR for this, can you make it? Therefore I would merge it quickly

micheleb commented 1 year ago

Hey @loicortola, thanks for replying so quickly :)

I created a PR with my workaround, it's not much, but at least it prevents the NPE.

loicortola commented 1 year ago

Merged and released, let me know if everything works as expected!

micheleb commented 1 year ago

thanks! I released the fix in the wild, will report back next week on how it's going 🤞🏻

micheleb commented 1 year ago

Hey @loicortola, just dropped by to confirm that we're no longer seeing the NPE crashes 👌🏻 Cheers!

loicortola commented 1 year ago

Thanks @micheleb