From ec21ce425f4e5637be716406f9d0e038921550d7 Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Tue, 16 May 2017 19:51:04 -0700 Subject: [PATCH] HDFS-11827. NPE is thrown when log level changed in BlockPlacementPolicyDefault#chooseRandom() method. Contributed by xupeng. --- .../server/blockmanagement/BlockPlacementPolicyDefault.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java index a245f0c006..a47939726a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyDefault.java @@ -735,7 +735,7 @@ protected DatanodeStorageInfo chooseRandom(int numOfReplicas, } Preconditions.checkState(excludedNodes.add(chosenNode), "chosenNode " + chosenNode + " is already in excludedNodes " + excludedNodes); - if (LOG.isDebugEnabled()) { + if (LOG.isDebugEnabled() && builder != null) { builder.append("\nNode ").append(NodeBase.getPath(chosenNode)) .append(" ["); } @@ -771,7 +771,7 @@ protected DatanodeStorageInfo chooseRandom(int numOfReplicas, } } - if (LOG.isDebugEnabled()) { + if (LOG.isDebugEnabled() && builder != null) { builder.append("\n]"); }