From 7640414e8df66072ec43c4f3148e2ad17e494806 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 10 Dec 2014 12:36:35 +0100 Subject: [PATCH] Set conditionText to null if it's the empty string This fixes e.g. IllegalArgumentException "'conflict' can not contain a condition text", when receiving elements like Replaced by new connection (ejabberd does this) --- .../java/org/jivesoftware/smack/packet/StreamError.java | 7 +++++++ .../main/java/org/jivesoftware/smack/packet/XMPPError.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java index b58c42621..631926d2f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java @@ -20,6 +20,7 @@ package org.jivesoftware.smack.packet; import java.util.List; import java.util.Map; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.XmlStringBuilder; /** @@ -105,6 +106,12 @@ public class StreamError extends AbstractError implements PlainStreamElement { public StreamError(Condition condition, String conditionText, Map descriptiveTexts, List extensions) { super(descriptiveTexts, extensions); + // Some implementations may send the condition as non-empty element containing the empty string, that is + // , in this case the parser may calls this constructor with the empty string + // as conditionText, therefore reset it to null if it's the empty string + if (StringUtils.isNullOrEmpty(conditionText)) { + conditionText = null; + } if (conditionText != null) { switch (condition) { case see_other_host: diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index 73496a148..15b235c12 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.logging.Logger; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.XmlStringBuilder; /** @@ -117,6 +118,12 @@ public class XMPPError extends AbstractError { List extensions) { super(descriptiveTexts, NAMESPACE, extensions); this.condition = condition; + // Some implementations may send the condition as non-empty element containing the empty string, that is + // , in this case the parser may calls this constructor with the empty string + // as conditionText, therefore reset it to null if it's the empty string + if (StringUtils.isNullOrEmpty(conditionText)) { + conditionText = null; + } if (conditionText != null) { switch (condition) { case gone: