aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-08-27 17:13:33 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-08-27 17:13:42 +0200
commit8030eabc147325e24fadd12653edf23cdff51545 (patch)
tree3259a68ea334d7db1005ec140cca64240b48f950
parentdc56eff40ee939c2e06ad0e33fd62b27e64f8fb8 (diff)
downloadsonarqube-8030eabc147325e24fadd12653edf23cdff51545.tar.gz
sonarqube-8030eabc147325e24fadd12653edf23cdff51545.zip
SONAR-4898 do not use IPv6 loopback address
Conflict with -Djava.net.preferIPv4Stack=true recommended for ES
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java10
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java2
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");
}
}
}