From 5fcfe548f9618b8362b5201f76ba681c453a2aff Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 31 Oct 2014 00:24:26 +0100 Subject: [PATCH] Validate ProviderManager arguments --- .../smack/provider/ProviderManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderManager.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderManager.java index 1b8abc953..66a694048 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderManager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderManager.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.util.StringUtils; import org.jxmpp.util.XmppStringUtils; /** @@ -202,6 +203,7 @@ public final class ProviderManager { public static void addIQProvider(String elementName, String namespace, Object provider) { + validate(elementName, namespace); // First remove existing providers String key = removeIQProvider(elementName, namespace); if (provider instanceof IQProvider) { @@ -272,6 +274,7 @@ public final class ProviderManager { public static void addExtensionProvider(String elementName, String namespace, Object provider) { + validate(elementName, namespace); // First remove existing providers String key = removeExtensionProvider(elementName, namespace); if (provider instanceof PacketExtensionProvider) { @@ -320,6 +323,7 @@ public final class ProviderManager { } public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider provider) { + validate(elementName, namespace); String key = getKey(elementName, namespace); streamFeatureProviders.put(key, provider); } @@ -332,4 +336,13 @@ public final class ProviderManager { private static String getKey(String elementName, String namespace) { return XmppStringUtils.generateKey(elementName, namespace); } + + private static void validate(String elementName, String namespace) { + if (StringUtils.isNullOrEmpty(elementName)) { + throw new IllegalArgumentException("elementName must not be null or empty"); + } + if (StringUtils.isNullOrEmpty(namespace)) { + throw new IllegalArgumentException("namespace must not be null or empty"); + } + } }