From 2ba4c4eb9fe568b962f9d71de829531f51c5375b Mon Sep 17 00:00:00 2001 From: anoopsjohn Date: Tue, 21 Apr 2015 17:34:09 +0530 Subject: [PATCH] HBASE-13520 NullPointerException in TagRewriteCell.(Josh Elser) --- .../apache/hadoop/hbase/TagRewriteCell.java | 5 ++ .../hadoop/hbase/TestTagRewriteCell.java | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/TestTagRewriteCell.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/TagRewriteCell.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/TagRewriteCell.java index 313ecb8b586..eb6d3bef82f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/TagRewriteCell.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/TagRewriteCell.java @@ -41,6 +41,7 @@ public class TagRewriteCell implements Cell, SettableSequenceId, SettableTimesta public TagRewriteCell(Cell cell, byte[] tags) { assert cell instanceof SettableSequenceId; assert cell instanceof SettableTimestamp; + assert tags != null; this.cell = cell; this.tags = tags; // tag offset will be treated as 0 and length this.tags.length @@ -143,6 +144,10 @@ public class TagRewriteCell implements Cell, SettableSequenceId, SettableTimesta @Override public int getTagsLength() { + if (null == this.tags) { + // Nulled out tags array optimization in constructor + return 0; + } return this.tags.length; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestTagRewriteCell.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestTagRewriteCell.java new file mode 100644 index 00000000000..56cecf4ca40 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestTagRewriteCell.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import static org.junit.Assert.assertTrue; + +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestTagRewriteCell { + + @Test + public void testHeapSize() { + Cell originalCell = CellUtil.createCell(Bytes.toBytes("row"), Bytes.toBytes("value")); + final int fakeTagArrayLength = 10; + TagRewriteCell trCell = new TagRewriteCell(originalCell, new byte[fakeTagArrayLength]); + + // Get the heapSize before the internal tags array in trCell are nuked + long trCellHeapSize = trCell.heapSize(); + + // Make another TagRewriteCell with the original TagRewriteCell + // This happens on systems with more than one RegionObserver/Coproc loaded (such as + // VisibilityController and AccessController) + TagRewriteCell trCell2 = new TagRewriteCell(trCell, new byte[fakeTagArrayLength]); + + assertTrue("TagRewriteCell containing a TagRewriteCell's heapsize should be larger than a " + + "single TagRewriteCell's heapsize", trCellHeapSize < trCell2.heapSize()); + assertTrue("TagRewriteCell should have had nulled out tags array", trCell.heapSize() < + trCellHeapSize); + } +}