diff --git a/src/main/java/io/vertx/core/dns/impl/DnsClientImpl.java b/src/main/java/io/vertx/core/dns/impl/DnsClientImpl.java index eeda3dc4274..1cd5fc8913c 100644 --- a/src/main/java/io/vertx/core/dns/impl/DnsClientImpl.java +++ b/src/main/java/io/vertx/core/dns/impl/DnsClientImpl.java @@ -14,6 +14,7 @@ import io.netty.channel.*; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.InternetProtocolFamily; +import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.dns.*; import io.netty.handler.logging.LoggingHandler; import io.netty.util.collection.LongObjectHashMap; @@ -261,7 +262,14 @@ void handle(DnsResponse msg) { List records = new ArrayList<>(count); for (int idx = 0;idx < count;idx++) { DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx); - T record = RecordDecoder.decode(a); + T record; + try { + record = RecordDecoder.decode(a); + } catch (DecoderException e) { + fail(e); + return; + } + if (isRequestedType(a.type(), types)) { records.add(record); } diff --git a/src/main/java/io/vertx/core/dns/impl/decoder/RecordDecoder.java b/src/main/java/io/vertx/core/dns/impl/decoder/RecordDecoder.java index 741badbff8b..0edfd09763e 100644 --- a/src/main/java/io/vertx/core/dns/impl/decoder/RecordDecoder.java +++ b/src/main/java/io/vertx/core/dns/impl/decoder/RecordDecoder.java @@ -222,7 +222,7 @@ public static T decode(DnsRecord record) { DnsRecordType type = record.type(); Function decoder = decoders.get(type); if (decoder == null) { - throw new IllegalStateException("Unsupported resource record type [id: " + type + "]."); + throw new DecoderException("DNS record decoding error occurred: Unsupported resource record type [id: " + type + "]."); } T result = null; try {