Added null safety if user set a bad ipv6 address
This commit is contained in:
parent
d196e69b23
commit
8777f12972
@ -182,12 +182,17 @@ public class DeviceConnectivityUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getHost(String baseUrl, DeviceConnectivityInfo properties, String protocol) throws URISyntaxException {
|
public static String getHost(String baseUrl, DeviceConnectivityInfo properties, String protocol) throws URISyntaxException {
|
||||||
String host = properties.getHost().isEmpty() ? baseUrl : properties.getHost();
|
String initialHost = properties.getHost().isEmpty() ? baseUrl : properties.getHost();
|
||||||
InetAddress inetAddress;
|
InetAddress inetAddress;
|
||||||
if (VALID_URL_PATTERN.matcher(host).matches()) {
|
String host = null;
|
||||||
host = new URI(host).getHost();
|
if (VALID_URL_PATTERN.matcher(initialHost).matches()) {
|
||||||
|
host = new URI(initialHost).getHost();
|
||||||
|
}
|
||||||
|
if (host == null) {
|
||||||
|
host = initialHost;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
host = host.replaceAll("^https?://", "");
|
||||||
inetAddress = InetAddress.getByName(host);
|
inetAddress = InetAddress.getByName(host);
|
||||||
host = inetAddress.getHostName();
|
host = inetAddress.getHostName();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user