1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 07:22:07 +01:00

Verify ConnectionConfiguration parameters

also fix javadoc error for StringUtils.isNullOrEmpty()

Fixes SMACK-539
This commit is contained in:
Florian Schmaus 2014-08-01 23:20:35 +02:00
parent 66da4dfa91
commit a574e1d56d
2 changed files with 20 additions and 3 deletions

View file

@ -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<HostAddress>(1);
HostAddress hostAddress;
hostAddress = new HostAddress(host, port);

View file

@ -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;
}
}