From c4228e072b7bcbc93d16cbd0b92577044cc3f22b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 14 Nov 2020 12:44:42 +0100 Subject: [PATCH] [tcp] Add missing null check in resolveDomain() The method lookupHostAddress() returns null in case of an error, hence we need to test if the returned value is null prior adding the endpoint. Should fix the following NPE: java.lang.NullPointerException: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration (XMPPTCPConnection.java:606) at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal (XMPPTCPConnection.java:846) at org.jivesoftware.smack.AbstractXMPPConnection.connect (AbstractXMPPConnection.java:530) at org.jivesoftware.smack.ReconnectionManager$2.run (ReconnectionManager.java:282) at java.lang.Thread.run (Thread.java:784) Reported-by: Eng ChongMeng --- .../smack/tcp/rce/RemoteXmppTcpConnectionEndpoints.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/rce/RemoteXmppTcpConnectionEndpoints.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/rce/RemoteXmppTcpConnectionEndpoints.java index 6b7da5ccf..71187155b 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/rce/RemoteXmppTcpConnectionEndpoints.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/rce/RemoteXmppTcpConnectionEndpoints.java @@ -192,8 +192,10 @@ public class RemoteXmppTcpConnectionEndpoints { for (SRV srv : sortedSrvRecords) { List targetInetAddresses = dnsResolver.lookupHostAddress(srv.target, lookupFailures, dnssecMode); - SrvXmppRemoteConnectionEndpoint endpoint = new SrvXmppRemoteConnectionEndpoint(srv, targetInetAddresses); - endpoints.add(endpoint); + if (targetInetAddresses != null) { + SrvXmppRemoteConnectionEndpoint endpoint = new SrvXmppRemoteConnectionEndpoint(srv, targetInetAddresses); + endpoints.add(endpoint); + } } } else { LOGGER.info("Could not resolve DNS SRV resource records for " + srvDomain + ". Consider adding those.");