From 609846b8889b9e636500272ffeb8cde3b2ebb4ab Mon Sep 17 00:00:00 2001 From: Elliott Clark Date: Mon, 7 Jan 2013 16:52:23 -0800 Subject: [PATCH] fix throwing NPE when creating BlocksDistribution. --- .../java/org/apache/hadoop/hbase/HDFSBlocksDistribution.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/HDFSBlocksDistribution.java hbase-server/src/main/java/org/apache/hadoop/hbase/HDFSBlocksDistribution.java index f9be768..19cdd29 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/HDFSBlocksDistribution.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/HDFSBlocksDistribution.java @@ -122,8 +122,11 @@ public class HDFSBlocksDistribution { */ public void addHostsAndBlockWeight(String[] hosts, long weight) { if (hosts == null || hosts.length == 0) { - throw new NullPointerException("empty hosts"); + // Bail out early if there are no hosts. Since everything is already + // pre-initialized bailing out early is just like not adding the weight at all. + return; } + addUniqueWeight(weight); for (String hostname : hosts) { addHostAndBlockWeight(hostname, weight); @@ -146,7 +149,9 @@ public class HDFSBlocksDistribution { */ private void addHostAndBlockWeight(String host, long weight) { if (host == null) { - throw new NullPointerException("Passed hostname is null"); + // Bail out early if there is no host. Since everything is already + // pre-initialized bailing out early is just like not adding the weight at all. + return; } HostAndWeight hostAndWeight = this.hostAndWeights.get(host); -- 1.7.10.2 (Apple Git-33)