Skip to content

Commit

Permalink
fix: 🐛 avoid NPE when connect on windows
Browse files Browse the repository at this point in the history
or with no access to the conf file : /etc/resolv.conf

(cherry picked from commit 06ff785)
  • Loading branch information
Liuigi authored and gsmet committed Oct 18, 2022
1 parent 1fa6489 commit 20eee46
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class MongoDnsClient implements DnsClient {

private static List<String> nameServers() {
Path conf = Paths.get("/etc/resolv.conf");
List<String> nameServers = null;
List<String> nameServers = Collections.emptyList();
if (Files.exists(conf)) {
try (Stream<String> lines = Files.lines(conf)) {
nameServers = lines
Expand All @@ -91,7 +92,6 @@ private static List<String> 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;
Expand Down

0 comments on commit 20eee46

Please sign in to comment.