resourcepool/ssdp-client

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

Closed this issue · 6 comments

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?).

Hi @micheleb ,

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

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.

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

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

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