From: Simon Brandhof Date: Wed, 27 Aug 2014 15:13:33 +0000 (+0200) Subject: SONAR-4898 do not use IPv6 loopback address X-Git-Tag: 4.5-RC1~72 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8030eabc147325e24fadd12653edf23cdff51545;p=sonarqube.git SONAR-4898 do not use IPv6 loopback address Conflict with -Djava.net.preferIPv4Stack=true recommended for ES --- diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java b/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java index da70cac778c..17366850be3 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java @@ -20,7 +20,6 @@ package org.sonar.process; import java.net.Inet4Address; -import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; @@ -35,8 +34,9 @@ public class LoopbackAddress { } /** - * Similar to InetAddress.getLoopbackAddress() which was introduced in Java 7. This - * method aims to support Java 6. + * Quite similar to InetAddress.getLoopbackAddress() which was introduced in Java 7. This + * method aims to support Java 6. It returns an IPv4 address, but not IPv6 in order to + * support -Djava.net.preferIPv4Stack=true recommended for Elasticsearch */ public static InetAddress get() { if (instance == null) { @@ -57,14 +57,14 @@ public class LoopbackAddress { Enumeration addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); - if (addr.isLoopbackAddress()) { + if (addr.isLoopbackAddress() && addr instanceof Inet4Address) { result = addr; break; } } } if (result == null) { - throw new IllegalStateException("Impossible to get a IP loopback address"); + throw new IllegalStateException("Impossible to get a IPv4 loopback address"); } return result; } diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java index 0e4885a6407..6a8819c3a81 100644 --- a/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java +++ b/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java @@ -45,7 +45,7 @@ public class LoopbackAddressTest { LoopbackAddress.doGet(ifaces); fail(); } catch (IllegalStateException e) { - assertThat(e).hasMessage("Impossible to get a IP loopback address"); + assertThat(e).hasMessage("Impossible to get a IPv4 loopback address"); } } }