diff options
-rw-r--r-- | server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java | 10 | ||||
-rw-r--r-- | server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java | 2 |
2 files changed, 6 insertions, 6 deletions
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<InetAddress> 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"); } } } |