From f2fb2f6dea88d72980b5089884c3b07feaeaccd8 Mon Sep 17 00:00:00 2001 From: chenheng Date: Wed, 21 Oct 2015 17:42:48 +0800 Subject: [PATCH] HBASE-14662 Fix NPE in HFileOutputFormat2 --- .../hadoop/hbase/mapreduce/HFileOutputFormat2.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java index 388c017..a183773 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java @@ -210,15 +210,16 @@ public class HFileOutputFormat2 if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, DEFAULT_LOCALITY_SENSITIVE)) { HRegionLocation loc = null; String tableName = conf.get(OUTPUT_TABLE_NAME_CONF_KEY); - - try (Connection connection = ConnectionFactory.createConnection(conf); - RegionLocator locator = - connection.getRegionLocator(TableName.valueOf(tableName))) { - loc = locator.getRegionLocation(rowKey); - } catch (Throwable e) { - LOG.warn("there's something wrong when locating rowkey: " + - Bytes.toString(rowKey), e); - loc = null; + if (tableName != null) { + try (Connection connection = ConnectionFactory.createConnection(conf); + RegionLocator locator = + connection.getRegionLocator(TableName.valueOf(tableName))) { + loc = locator.getRegionLocation(rowKey); + } catch (Throwable e) { + LOG.warn("there's something wrong when locating rowkey: " + + Bytes.toString(rowKey), e); + loc = null; + } } if (null == loc) { -- 1.9.3 (Apple Git-50)