HDFS-12832. INode.getFullPathName may throw ArrayIndexOutOfBoundsException lead to NameNode exit. Contribuited by Konstantin Shvachko.

(cherry picked from commit d331762f24b3f22f609366740c9c4f449edc61ac)
(cherry picked from commit 3219b1bdf6d6a8a86ed1db1491df63a4748ad6de)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
index 3cc66bf..e2bdfcb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java
@@ -1527,8 +1527,6 @@
       }
 
       // choose replication targets: NOT HOLDING THE GLOBAL LOCK
-      // It is costly to extract the filename for which chooseTargets is called,
-      // so for now we pass in the block collection itself.
       rw.chooseTargets(blockplacement, storagePolicySuite, excludedNodes);
     }
 
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ReplicationWork.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ReplicationWork.java
index 258dfdd..8362096 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ReplicationWork.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ReplicationWork.java
@@ -25,7 +25,8 @@
 
 class ReplicationWork {
   private final BlockInfo block;
-  private final BlockCollection bc;
+  private final String srcPath;
+  private final byte storagePolicyID;
   private final DatanodeDescriptor srcNode;
   private final int additionalReplRequired;
   private final int priority;
@@ -38,7 +39,8 @@
       List<DatanodeStorageInfo> liveReplicaStorages, int additionalReplRequired,
       int priority) {
     this.block = block;
-    this.bc = bc;
+    this.srcPath = bc.getName();
+    this.storagePolicyID = bc.getStoragePolicyID();
     this.srcNode = srcNode;
     this.srcNode.incrementPendingReplicationWithoutTargets();
     this.containingNodes = containingNodes;
@@ -52,10 +54,10 @@
       BlockStoragePolicySuite storagePolicySuite,
       Set<Node> excludedNodes) {
     try {
-      targets = blockplacement.chooseTarget(bc.getName(),
+      targets = blockplacement.chooseTarget(getSrcPath(),
           additionalReplRequired, srcNode, liveReplicaStorages, false,
           excludedNodes, block.getNumBytes(),
-          storagePolicySuite.getPolicy(bc.getStoragePolicyID()), null);
+          storagePolicySuite.getPolicy(getStoragePolicyID()), null);
     } finally {
       srcNode.decrementPendingReplicationWithoutTargets();
     }
@@ -84,4 +86,12 @@
   public DatanodeDescriptor getSrcNode() {
     return srcNode;
   }
+
+  public String getSrcPath() {
+    return srcPath;
+  }
+
+  public byte getStoragePolicyID() {
+    return storagePolicyID;
+  }
 }