瀏覽代碼

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
tags/10.5.0.89998
Julien HENRY 1 月之前
父節點
當前提交
dda2bcce92
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5
    1
      server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java

+ 5
- 1
server/sonar-process/src/main/java/org/sonar/process/NetworkUtilsImpl.java 查看文件

@@ -124,7 +124,11 @@ public class NetworkUtilsImpl implements NetworkUtils {
try {
Optional<InetAddress> 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) {

Loading…
取消
儲存