1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-07 13:41:08 +01:00

Ensure that connection is authenticated in PingManager

This commit is contained in:
Florian Schmaus 2014-09-29 15:56:50 +02:00
parent 50e068b6a7
commit 7521ef951a
2 changed files with 51 additions and 20 deletions

View file

@ -177,9 +177,15 @@ public class PingManager extends Manager {
* @throws NotConnectedException
*/
public boolean ping(String jid, long pingTimeout) throws NotConnectedException, NoResponseException {
final XMPPConnection connection = connection();
// Packet collector for IQs needs an connection that was at least authenticated once,
// otherwise the client JID will be null causing an NPE
if (!connection.isAuthenticated()) {
throw new NotConnectedException();
}
Ping ping = new Ping(jid);
try {
connection().createPacketCollectorAndSend(ping).nextResultOrThrow(pingTimeout);
connection.createPacketCollectorAndSend(ping).nextResultOrThrow(pingTimeout);
}
catch (XMPPException exc) {
return jid.equals(connection().getServiceName());