diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/BasicInetPeer.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/BasicInetPeer.java index f18c5a0c1e..b9f4e24d15 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/BasicInetPeer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/BasicInetPeer.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import java.net.SocketAddress; import java.nio.channels.ReadableByteChannel; import org.apache.hadoop.net.unix.DomainSocket; @@ -93,7 +94,8 @@ public void close() throws IOException { @Override public String getRemoteAddressString() { - return socket.getRemoteSocketAddress().toString(); + SocketAddress address = socket.getRemoteSocketAddress(); + return address == null ? null : address.toString(); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/NioInetPeer.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/NioInetPeer.java index 23a45b7fe4..164f31e37a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/NioInetPeer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/net/NioInetPeer.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import java.net.SocketAddress; import java.nio.channels.ReadableByteChannel; import org.apache.hadoop.net.SocketInputStream; @@ -96,7 +97,8 @@ public void close() throws IOException { @Override public String getRemoteAddressString() { - return socket.getRemoteSocketAddress().toString(); + SocketAddress address = socket.getRemoteSocketAddress(); + return address == null ? null : address.toString(); } @Override