From cfee749ea0ad92ea3be06d0a271c92de283ba375 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 5 Apr 2018 16:51:10 +0300 Subject: [PATCH] IDEA-189608 Handle possible misconfiguration of loopback interface --- .../intellij/execution/rmi/RemoteServer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/platform/util-rt/src/com/intellij/execution/rmi/RemoteServer.java b/platform/util-rt/src/com/intellij/execution/rmi/RemoteServer.java index d11891b1f594..25d63b38f6d8 100644 --- a/platform/util-rt/src/com/intellij/execution/rmi/RemoteServer.java +++ b/platform/util-rt/src/com/intellij/execution/rmi/RemoteServer.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.net.Inet6Address; import java.net.InetAddress; import java.net.ServerSocket; import java.rmi.Remote; @@ -37,6 +38,9 @@ import java.util.Hashtable; import java.util.Random; public class RemoteServer { + + public static final String SERVER_HOSTNAME = "java.rmi.server.hostname"; + static { // Radar #5755208: Command line Java applications need a way to launch without a Dock icon. System.setProperty("apple.awt.UIElement", "true"); @@ -104,7 +108,9 @@ public class RemoteServer { // if we are behind a firewall, if the network connection is lost, etc. // do not use domain or http address for server - System.setProperty("java.rmi.server.hostname", "localhost"); + if (System.getProperty(SERVER_HOSTNAME) == null) { + System.setProperty(SERVER_HOSTNAME, getLoopbackAddress()); + } // do not use HTTP tunnelling System.setProperty("java.rmi.server.disableHttp", "true"); } @@ -124,6 +130,16 @@ public class RemoteServer { } } + @NotNull + private static String getLoopbackAddress() { + boolean ipv6 = false; + try { + ipv6 = InetAddress.getByName(null) instanceof Inet6Address; + } + catch (IOException ignore) {} + return ipv6 ? "::1" : "127.0.0.1"; + } + @SuppressWarnings("UnusedDeclaration") public static class Jndi implements InitialContextFactory, InvocationHandler { @NotNull