diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java index e0eb98aed..e56b0a185 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2013-2016 Florian Schmaus + * Copyright © 2013-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import java.util.Map; import java.util.Map.Entry; import org.jivesoftware.smack.SmackException.ConnectionException; -import org.jivesoftware.smack.util.Objects; +import org.jivesoftware.smack.util.StringUtils; public class HostAddress { private final String fqdn; @@ -34,18 +34,17 @@ public class HostAddress { private final List inetAddresses; /** - * Creates a new HostAddress with the given FQDN. The port will be set to the default XMPP client port: 5222 + * Creates a new HostAddress with the given FQDN. * - * @param fqdn Fully qualified domain name. + * @param fqdn the optional fully qualified domain name (FQDN). * @param port The port to connect on. - * @throws IllegalArgumentException If the fqdn is null or port is out of valid range (0 - 65535). + * @throws IllegalArgumentException If the port is out of valid range (0 - 65535). */ public HostAddress(String fqdn, int port, List inetAddresses) { - Objects.requireNonNull(fqdn, "FQDN is null"); if (port < 0 || port > 65535) throw new IllegalArgumentException( "Port must be a 16-bit unsiged integer (i.e. between 0-65535. Port was: " + port); - if (fqdn.charAt(fqdn.length() - 1) == '.') { + if (StringUtils.isNotEmpty(fqdn) && fqdn.charAt(fqdn.length() - 1) == '.') { this.fqdn = fqdn.substring(0, fqdn.length() - 1); } else { @@ -59,7 +58,7 @@ public class HostAddress { } public HostAddress(int port, InetAddress hostAddress) { - this("", port, Collections.singletonList(hostAddress)); + this(null, port, Collections.singletonList(hostAddress)); } /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java index e84d846de..f63c94e49 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/SRVRecord.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013-2016 Florian Schmaus + * Copyright 2013-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ package org.jivesoftware.smack.util.dns; import java.net.InetAddress; import java.util.List; +import org.jivesoftware.smack.util.StringUtils; + /** * A DNS SRV RR. * @@ -43,6 +45,7 @@ public class SRVRecord extends HostAddress implements Comparable { */ public SRVRecord(String fqdn, int port, int priority, int weight, List inetAddresses) { super(fqdn, port, inetAddresses); + StringUtils.requireNotNullOrEmpty(fqdn, "The FQDN must not be null"); if (weight < 0 || weight > 65535) throw new IllegalArgumentException( "DNS SRV records weight must be a 16-bit unsiged integer (i.e. between 0-65535. Weight was: " diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 61fe86a3b..2080c100a 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -593,6 +593,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { } failedAddresses.add(hostAddress); } else { + StringUtils.requireNotNullOrEmpty(host, "Host of HostAddress " + hostAddress + " must not be null when using a Proxy"); final String hostAndPort = host + " at port " + port; LOGGER.finer("Trying to establish TCP connection via Proxy to " + hostAndPort); try {