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 f18c5a0c1ee..b9f4e24d15c 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.IOException; 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 class BasicInetPeer implements Peer { @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 23a45b7fe45..164f31e37ad 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.IOException; 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 class NioInetPeer implements Peer { @Override public String getRemoteAddressString() { - return socket.getRemoteSocketAddress().toString(); + SocketAddress address = socket.getRemoteSocketAddress(); + return address == null ? null : address.toString(); } @Override