From d48da69185884ad36047633b47e7d61723c8a4e8 Mon Sep 17 00:00:00 2001 From: Sakthi Date: Fri, 23 Feb 2018 12:09:19 -0800 Subject: [PATCH] HBASE-18864 Fixed NullPointerException thrown while adding rows to a table from peer cluster, with replication factor other than 0 or 1 --- .../src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java | 9 +++++++++ .../test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index 6cd047a97b9c0f433547da5f0be622d619d739bd..12442a0018bac20596fb5d184f3ec6abf2f8d302 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.BytesBytesPair; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ColumnFamilySchema; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair; +import org.apache.hadoop.hbase.protobuf.generated.WALProtos; import org.apache.hadoop.hbase.regionserver.BloomType; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.PrettyPrinter; @@ -570,6 +571,14 @@ public class HColumnDescriptor implements WritableComparable public HColumnDescriptor setValue(byte[] key, byte[] value) { if (Bytes.compareTo(Bytes.toBytes(HConstants.VERSIONS), key) == 0) { cachedMaxVersions = UNINITIALIZED; + } else if (Bytes.compareTo(REPLICATION_SCOPE_BYTES, key) == 0) { + // as bytes are encoded from string, we have to decode value as string + int scopeType = Integer.valueOf(Bytes.toString(value)); + if (scopeType != WALProtos.ScopeType.REPLICATION_SCOPE_GLOBAL_VALUE && + scopeType != WALProtos.ScopeType.REPLICATION_SCOPE_LOCAL_VALUE) { + throw new IllegalArgumentException("Invalid value '" + scopeType + + "' for REPLICATION_SCOPE."); + } } values.put(new ImmutableBytesWritable(key), new ImmutableBytesWritable(value)); diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java index 1966253a0f3bea33c5840d3a5e46e46ca6eb3717..1a27f87f8591ea5e7a76ce22d8531d1373bc0e91 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHColumnDescriptor.java @@ -113,4 +113,10 @@ public class TestHColumnDescriptor { BuilderStyleTest.assertClassesAreBuilderStyle(HColumnDescriptor.class); } + + @Test(expected=IllegalArgumentException.class) + public void testInvalidReplicationScope() { + HColumnDescriptor column = new HColumnDescriptor("f1"); + column.setScope(5); + } } -- 2.16.2