From a2340f52ec8b6b951b389096f83ff92da4d26b9d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 13 Apr 2016 11:37:31 +0200 Subject: [PATCH] use InetAddress.getLoopbackAddress() --- .../src/com/intellij/compiler/server/BuildManager.java | 5 +++-- .../com/intellij/execution/runners/ProcessProxyImpl.java | 6 +++--- .../platform-api/src/com/intellij/util/net/NetUtils.java | 9 ++------- .../platform-impl/src/com/intellij/idea/SocketLock.java | 6 +++--- .../io/socketConnection/impl/SocketConnectionImpl.java | 7 +++---- .../src/org/jetbrains/io/BuiltInServer.java | 3 +-- .../intellij/lang/xpath/xslt/run/OutputTabAdapter.java | 4 ++-- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 2d9742863629..3983bf2b36ab 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -112,6 +112,7 @@ import java.awt.*; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.charset.Charset; import java.text.SimpleDateFormat; @@ -1205,7 +1206,7 @@ public class BuildManager implements Disposable { catch (Throwable e) { LOG.error(e); } - + final OSProcessHandler processHandler = new OSProcessHandler(cmdLine) { @Override protected boolean shouldDestroyProcessRecursively() { @@ -1336,7 +1337,7 @@ public class BuildManager implements Disposable { myMessageDispatcher); } }); - Channel serverChannel = bootstrap.bind(NetUtils.getLoopbackAddress(), 0).syncUninterruptibly().channel(); + Channel serverChannel = bootstrap.bind(InetAddress.getLoopbackAddress(), 0).syncUninterruptibly().channel(); myChannelRegistrar.add(serverChannel); return ((InetSocketAddress)serverChannel.localAddress()).getPort(); } diff --git a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java index 525966359763..f09d7b553639 100644 --- a/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java +++ b/java/execution/impl/src/com/intellij/execution/runners/ProcessProxyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,13 @@ package com.intellij.execution.runners; import com.intellij.execution.process.ProcessHandler; import com.intellij.openapi.util.Key; -import com.intellij.util.net.NetUtils; import org.jetbrains.annotations.NonNls; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; @@ -95,7 +95,7 @@ class ProcessProxyImpl implements ProcessProxy { if (myWriter == null) { try { if (mySocket == null) { - mySocket = new Socket(NetUtils.getLoopbackAddress(), myPortNumber); + mySocket = new Socket(InetAddress.getLoopbackAddress(), myPortNumber); } myWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mySocket.getOutputStream()))); } diff --git a/platform/platform-api/src/com/intellij/util/net/NetUtils.java b/platform/platform-api/src/com/intellij/util/net/NetUtils.java index c261cea5d7ef..f62c0f750d91 100644 --- a/platform/platform-api/src/com/intellij/util/net/NetUtils.java +++ b/platform/platform-api/src/com/intellij/util/net/NetUtils.java @@ -33,12 +33,6 @@ public class NetUtils { private NetUtils() { } - /** @deprecated use {@link #canConnectToSocket(String, int)} (to be remove in IDEA 17) */ - @SuppressWarnings("unused") - public static boolean canConnectToSocketOpenedByJavaProcess(String host, int port) { - return canConnectToSocket(host, port); - } - public static boolean canConnectToSocket(String host, int port) { if (isLocalhost(host)) { return !canBindToLocalSocket(host, port); @@ -48,6 +42,7 @@ public class NetUtils { } } + @Deprecated public static InetAddress getLoopbackAddress() { return InetAddress.getLoopbackAddress(); } @@ -218,6 +213,6 @@ public class NetUtils { } public static boolean isSniEnabled() { - return SystemInfo.isJavaVersionAtLeast("1.7") && SystemProperties.getBooleanProperty("jsse.enableSNIExtension", true); + return SystemProperties.getBooleanProperty("jsse.enableSNIExtension", true); } } diff --git a/platform/platform-impl/src/com/intellij/idea/SocketLock.java b/platform/platform-impl/src/com/intellij/idea/SocketLock.java index 0e4585b9f5f3..783e761c1069 100644 --- a/platform/platform-impl/src/com/intellij/idea/SocketLock.java +++ b/platform/platform-impl/src/com/intellij/idea/SocketLock.java @@ -27,7 +27,6 @@ import com.intellij.util.Consumer; import com.intellij.util.NotNullProducer; import com.intellij.util.PlatformUtils; import com.intellij.util.containers.MultiMap; -import com.intellij.util.net.NetUtils; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.channel.ChannelHandler; @@ -40,6 +39,7 @@ import org.jetbrains.io.MessageDecoder; import java.io.*; import java.lang.management.ManagementFactory; import java.net.ConnectException; +import java.net.InetAddress; import java.net.Socket; import java.util.Collection; import java.util.List; @@ -189,7 +189,7 @@ public final class SocketLock { log("trying: port=%s", portNumber); args = checkForJetBrainsProtocolCommand(args); try { - Socket socket = new Socket(NetUtils.getLoopbackAddress(), portNumber); + Socket socket = new Socket(InetAddress.getLoopbackAddress(), portNumber); try { socket.setSoTimeout(1000); @@ -249,7 +249,7 @@ public final class SocketLock { private static void printPID(int port) { try { - Socket socket = new Socket(NetUtils.getLoopbackAddress(), port); + Socket socket = new Socket(InetAddress.getLoopbackAddress(), port); socket.setSoTimeout(1000); @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(PID_COMMAND); diff --git a/platform/platform-impl/src/com/intellij/util/io/socketConnection/impl/SocketConnectionImpl.java b/platform/platform-impl/src/com/intellij/util/io/socketConnection/impl/SocketConnectionImpl.java index cfe3db1224a6..5fc8fa284a29 100644 --- a/platform/platform-impl/src/com/intellij/util/io/socketConnection/impl/SocketConnectionImpl.java +++ b/platform/platform-impl/src/com/intellij/util/io/socketConnection/impl/SocketConnectionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package com.intellij.util.io.socketConnection.impl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.io.socketConnection.*; -import com.intellij.util.net.NetUtils; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -72,7 +71,7 @@ public class SocketConnectionImpl