diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Dispatcher.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Dispatcher.java index 9f9cdc0334179..37a10e69a2286 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Dispatcher.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Dispatcher.java @@ -286,7 +286,8 @@ private boolean chooseProxySource() { // if node group is supported, first try add nodes in the same node group if (cluster.isNodeGroupAware()) { for (StorageGroup loc : reportedBlock.getLocations()) { - if (cluster.isOnSameNodeGroup(loc.getDatanodeInfo(), targetDN) + //loc may throw NullPointerException + if (loc!=null && cluster.isOnSameNodeGroup(loc.getDatanodeInfo(), targetDN) && addTo(loc)) { return true; } @@ -294,13 +295,13 @@ && addTo(loc)) { } // check if there is replica which is on the same rack with the target for (StorageGroup loc : reportedBlock.getLocations()) { - if (cluster.isOnSameRack(loc.getDatanodeInfo(), targetDN) && addTo(loc)) { + if (loc!=null && cluster.isOnSameRack(loc.getDatanodeInfo(), targetDN) && addTo(loc)) { return true; } } // find out a non-busy replica for (StorageGroup loc : reportedBlock.getLocations()) { - if (addTo(loc)) { + if (loc!=null && addTo(loc)) { return true; } }