From 872b254db592c701838b9409c828418529963f82 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 30 Jan 2017 21:01:56 +0100 Subject: [PATCH] sendStanzaWithResponseCallback: Ensure exactly one callback is called --- .../org/jivesoftware/smack/AbstractXMPPConnection.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index bdfa066a2..2e8f5a5c5 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -1494,7 +1494,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { final StanzaListener packetListener = new StanzaListener() { @Override public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException { - removeAsyncStanzaListener(this); + boolean removed = removeAsyncStanzaListener(this); + if (!removed) { + // We lost a race against the "no response" handling runnable. Avoid calling the callback, as the + // exception callback will be invoked (if any). + return; + } try { XMPPErrorException.ifHasErrorThenThrow(packet); callback.processStanza(packet);