From 297bed106efdfa619d700ae44ce047d7f2663c93 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Fri, 26 Aug 2016 10:52:07 +0200 Subject: Fixes FS#230: Uncaught NullPointerException in DNSHelper --- .../conversationsplus/utils/DNSHelper.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java index 90618292..a0fd9995 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java @@ -135,15 +135,20 @@ public class DNSHelper { Logging.d("dns", "using dns server: " + dnsServerHostAddress + " to look up " + qname); try { DNSMessage message = client.query(qname, TYPE.SRV, CLASS.IN, dnsServerHostAddress); - Record[] rrset = message.getAnswers(); - for (Record rr : rrset) { - Data d = rr.getPayload(); - if (d instanceof SRV && NameUtil.idnEquals(qname, rr.getName())) { - SRV srv = (SRV) d; - SrvRecord srvRecord = new SrvRecord(srv.getPriority(), srv.getName(), srv.getPort(), tlsSrvRecord); - result.add(srvRecord); + if (null != message) { + Record[] rrset = message.getAnswers(); + for (Record rr : rrset) { + Data d = rr.getPayload(); + if (d instanceof SRV && NameUtil.idnEquals(qname, rr.getName())) { + SRV srv = (SRV) d; + SrvRecord srvRecord = new SrvRecord(srv.getPriority(), srv.getName(), srv.getPort(), tlsSrvRecord); + result.add(srvRecord); + } } + } else { + Logging.e("dns", "No valid DNS message retrieved."); } + } catch (IOException e) { Logging.d("dns", "Error while retrieving SRV record '" + qname + "' for '" + host + "' from DNS '" + dnsServerHostAddress + "': " + e.getMessage()); } -- cgit v1.2.3