From dda2bcce921549b20d7005e380dcc1bd5cdd6464 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 2 Apr 2024 12:19:09 +0200 Subject: [PATCH] SONAR-21971 Fix isLocal when multiple loopback adresses On my Ubuntu box, the hosts file contains: $ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 PC-L00XX And InetAddress.getLocalHost() returns 127.0.1.1, so the test isLocal_returns_true_on_localhost_address_or_host was failing --- .../src/main/java/org/sonar/process/NetworkUtilsImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java index cc020e16dfc..0a9765718f6 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java +++ b/server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java @@ -124,7 +124,11 @@ public class NetworkUtilsImpl implements NetworkUtils { try { Optional inetAddress = toInetAddress(hostOrAddress); if (inetAddress.isPresent()) { - return NetworkInterface.getByInetAddress(inetAddress.get()) != null; + var addr = inetAddress.get(); + if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { + return true; + } + return NetworkInterface.getByInetAddress(addr) != null; } return false; } catch (SocketException e) { -- 2.39.5