diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index f8e69533c..544f3ac48 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -20,6 +20,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.proxy.ProxyInfo; import org.jivesoftware.smack.util.DNSUtil; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.dns.HostAddress; import javax.net.SocketFactory; @@ -180,6 +181,9 @@ public class ConnectionConfiguration implements Cloneable { } protected void init(String serviceName, ProxyInfo proxy) { + if (StringUtils.isEmpty(serviceName)) { + throw new IllegalArgumentException("serviceName must not be the empty String"); + } this.serviceName = serviceName; this.proxy = proxy; @@ -597,6 +601,9 @@ public class ConnectionConfiguration implements Cloneable { } private void initHostAddresses(String host, int port) { + if (StringUtils.isEmpty(host)) { + throw new IllegalArgumentException("host must not be the empty String"); + } hostAddresses = new ArrayList(1); HostAddress hostAddress; hostAddress = new HostAddress(host, port); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java index 132e1d340..796b7ff1f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java @@ -528,12 +528,22 @@ public class StringUtils { } /** - * Returns true if the given CharSequence is not null or empty. + * Returns true if the given CharSequence is null or empty. * * @param cs - * @return true if the given CharSequence is not null or empty + * @return true if the given CharSequence is null or empty */ public static boolean isNullOrEmpty(CharSequence cs) { - return cs == null || cs.length() == 0; + return cs == null || isEmpty(cs); + } + + /** + * Returns true if the given CharSequence is empty + * + * @param cs + * @return true if the given CharSequence is empty + */ + public static boolean isEmpty(CharSequence cs) { + return cs.length() == 0; } }