diff --git a/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java b/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java index 14111003b..0f2e09fef 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java @@ -139,6 +139,7 @@ public class PacketCollector { */ @SuppressWarnings("unchecked") public

P nextResultBlockForever() { + throwIfCancelled(); P res = null; while (res == null) { try { @@ -171,6 +172,7 @@ public class PacketCollector { */ @SuppressWarnings("unchecked") public

P nextResult(long timeout) { + throwIfCancelled(); P res = null; long remainingWait = timeout; final long waitStart = System.currentTimeMillis(); @@ -243,4 +245,10 @@ public class PacketCollector { } } } + + private final void throwIfCancelled() { + if (cancelled) { + throw new IllegalStateException("Packet collector already cancelled"); + } + } }