diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index a6aa87aee..c3505f3ad 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -144,7 +144,6 @@ class PacketReader { */ public PacketCollector createPacketCollector(PacketFilter packetFilter) { PacketCollector packetCollector = new PacketCollector(this, packetFilter); - return packetCollector; } @@ -164,14 +163,18 @@ class PacketReader { } /** - * Removes a packet listener from this reader. + * Removes a packet listener. * * @param packetListener the packet listener to remove. */ public void removePacketListener(PacketListener packetListener) { synchronized (listeners) { - int index = listeners.indexOf(packetListener); - listeners.set(index, null); + for (int i=0; i 0) { + for (int i=listeners.size()-1; i>=0; i--) { + if (listeners.get(i) == null) { + listeners.remove(i); + } + } + } } processedPacket = false; int size = listeners.size(); @@ -300,7 +308,14 @@ class PacketReader { return; } - // TODO: loop through collectors and remove null values. + // Remove all null values from the collectors list. + synchronized (collectors) { + for (int i=collectors.size()-1; i<=0; i--) { + if (collectors.get(i) == null) { + collectors.remove(i); + } + } + } // Loop through all collectors and notify the appropriate ones. int size = collectors.size();