Null pointer exception in PingManager.pingMyServer

Hi all,

We are getting the following exception in our app.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method ‘long org.jivesoftware.smack.XMPPConnection.getPacketReplyTimeout()’ on a null object reference

at org.jivesoftware.smackx.ping.PingManager.pingMyServer(Unknown Source)

at org.jivesoftware.smackx.ping.PingManager.pingServerIfNecessary(Unknown Source)

at org.jivesoftware.smackx.ping.android.ServerPingWithAlarmManager$2$1.run(Unknown Source)

at java.lang.Thread.run(Thread.java:818)

If the connection is broken we will clear the connection and try to make a new one. And as the connection held in PingManager is a weak reference, it seemed that the reference to connection is becoming null and thus the exception occurred in pingMyServer when doing the retry.

Can anyone advise us how to handle the situation in a better way? Thanks in advance.

Thanks for reporting. Which version is this?

Dear Flow,

Thanks for your prompt reply. The version we are using is 4.1.6.

You should re-use the connection to preserve resources. I’ve uploaded Prevent GC of connection within pingServerIfNecessary() · Flowdalic/Smack@810e7c8 · GitHub for Smack 4.2 which should fix the issue.

I also recommend updating to the latest stable version of Smack, or even trying the latest 4.2 beta version (if it’s possible for you to run a beta version).