mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-25 15:52:06 +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:
parent
a574e1d56d
commit
d65d239550
1 changed files with 26 additions and 17 deletions
|
@ -156,20 +156,24 @@ public class OfflineMessageManager {
|
|||
}
|
||||
});
|
||||
PacketCollector messageCollector = connection.createPacketCollector(messageFilter);
|
||||
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||
// Collect the received offline messages
|
||||
Message message = (Message) messageCollector.nextResult();
|
||||
while (message != null) {
|
||||
messages.add(message);
|
||||
message = (Message) messageCollector.nextResult();
|
||||
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();
|
||||
}
|
||||
// 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);
|
||||
// Collect the received offline messages
|
||||
Message message = (Message) messageCollector.nextResult();
|
||||
while (message != null) {
|
||||
messages.add(message);
|
||||
message = (Message) messageCollector.nextResult();
|
||||
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();
|
||||
}
|
||||
// Stop queuing offline messages
|
||||
messageCollector.cancel();
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue