From 1f2183605cacac07ee99591761166a58f4687714 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 9 Mar 2014 15:36:02 +0100 Subject: [PATCH] Make IQReplyFilter aware of user-less connection state SMACK-533 --- .../jivesoftware/smack/filter/IQReplyFilter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java b/core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java index 63cbff7f4..bafe689e0 100644 --- a/core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java +++ b/core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java @@ -80,7 +80,13 @@ public class IQReplyFilter implements PacketFilter { */ public IQReplyFilter(IQ iqPacket, Connection conn) { to = iqPacket.getTo(); - local = conn.getUser().toLowerCase(); + if (conn.getUser() == null) { + // We have not yet been assigned a username, this can happen if the connection is + // in an early stage, i.e. when performing the SASL auth. + local = null; + } else { + local = conn.getUser().toLowerCase(); + } server = conn.getServiceName().toLowerCase(); packetId = iqPacket.getPacketID(); @@ -89,10 +95,11 @@ public class IQReplyFilter implements PacketFilter { OrFilter fromFilter = new OrFilter(); fromFilter.addFilter(FromMatchesFilter.createFull(to)); if (to == null) { - fromFilter.addFilter(FromMatchesFilter.createBare(local)); + if (local != null) + fromFilter.addFilter(FromMatchesFilter.createBare(local)); fromFilter.addFilter(FromMatchesFilter.createFull(server)); } - else if (to.toLowerCase().equals(StringUtils.parseBareAddress(local))) { + else if (local != null && to.toLowerCase().equals(StringUtils.parseBareAddress(local))) { fromFilter.addFilter(FromMatchesFilter.createFull(null)); } filter = new AndFilter(fromFilter, iqFilter, idFilter);