1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Make getMessages() set up collector *before* sending the request

Similar flaw was also fixed in 2c7f1efe80.

Also ensure that OfflineMessagesManager doesn't leak collector by using
a try/finally block.

Fixes SMACK-592
This commit is contained in:
Florian Schmaus 2014-08-04 12:19:58 +02:00
parent a574e1d56d
commit d65d239550

View file

@ -156,6 +156,7 @@ public class OfflineMessageManager {
}
});
PacketCollector messageCollector = connection.createPacketCollector(messageFilter);
try {
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
// Collect the received offline messages
Message message = (Message) messageCollector.nextResult();
@ -163,13 +164,16 @@ public class OfflineMessageManager {
messages.add(message);
message = (Message) messageCollector.nextResult();
}
}
finally {
// Stop queuing offline messages
messageCollector.cancel();
}
return messages;
}
/**
* Returns an Iterator with all the offline <tt>Messages</tt> of the user. The returned offline
* Returns a List of Messages with all the offline <tt>Messages</tt> of the user. The returned offline
* messages will not be deleted from the server. Use {@link #deleteMessages(java.util.List)}
* to delete the messages.
*
@ -183,17 +187,22 @@ public class OfflineMessageManager {
List<Message> messages = new ArrayList<Message>();
OfflineMessageRequest request = new OfflineMessageRequest();
request.setFetch(true);
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
PacketCollector messageCollector = connection.createPacketCollector(packetFilter);
try {
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
// Collect the received offline messages
Message message = (Message) messageCollector.nextResult();
while (message != null) {
messages.add(message);
message = (Message) messageCollector.nextResult();
}
}
finally {
// Stop queuing offline messages
messageCollector.cancel();
}
return messages;
}