From 3bb06b8429246a46a6c310819bb13130a41fbe82 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 3 Jul 2015 14:24:13 +0200 Subject: [PATCH] Wait in Roster's presence listener until Roster is loaded Fixes SMACK-681. --- .../main/java/org/jivesoftware/smack/roster/Roster.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java index 496fcae4e..ce481c952 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java @@ -1180,6 +1180,13 @@ public class Roster extends Manager { @Override public void processPacket(Stanza packet) throws NotConnectedException { + // Try to ensure that the roster is loaded when processing presence stanzas. While the + // presence listener is synchronous, the roster result listener is not, which means that + // the presence listener may be invoked with a not yet loaded roster. + boolean loaded = waitUntilLoaded(); + if (loaded) { + LOGGER.warning("Roster not loaded while processing presence stanza"); + } final XMPPConnection connection = connection(); Presence presence = (Presence) packet; String from = presence.getFrom();