From 20eee464874b3eb5335859bd190ca4018d8ccca5 Mon Sep 17 00:00:00 2001 From: Liuigi <78359902+liuigi@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:24:09 +0200 Subject: [PATCH] fix: :bug: avoid NPE when connect on windows or with no access to the conf file : /etc/resolv.conf (cherry picked from commit 06ff785629b0b4a23b5ec754eeed71a84ae03804) --- .../java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java index e12c70dc854b9..d20705bedaec5 100644 --- a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java +++ b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java @@ -8,6 +8,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -82,7 +83,7 @@ public class MongoDnsClient implements DnsClient { private static List nameServers() { Path conf = Paths.get("/etc/resolv.conf"); - List nameServers = null; + List nameServers = Collections.emptyList(); if (Files.exists(conf)) { try (Stream lines = Files.lines(conf)) { nameServers = lines @@ -91,7 +92,6 @@ private static List nameServers() { .collect(Collectors.toList()); } catch (IOException | ArrayIndexOutOfBoundsException e) { Logger.getLogger(MongoDnsClientProvider.class).info("Unable to read the /etc/resolv.conf file", e); - nameServers = new ArrayList<>(); } } return nameServers;