From 62ad9885ea8c75c134de43a3a925c76b253658e1 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Mon, 17 Jun 2019 20:18:53 -0700 Subject: [PATCH] HDFS-13730. BlockReaderRemote.sendReadResult throws NPE. Contributed by Yuanbo Liu. --- .../main/java/org/apache/hadoop/hdfs/net/BasicInetPeer.java | 4 +++- .../src/main/java/org/apache/hadoop/hdfs/net/NioInetPeer.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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