You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by an...@apache.org on 2015/04/21 14:04:29 UTC

hbase git commit: HBASE-13520 NullPointerException in TagRewriteCell.(Josh Elser)

Repository: hbase
Updated Branches:
  refs/heads/master eb82b8b30 -> 2ba4c4eb9


HBASE-13520 NullPointerException in TagRewriteCell.(Josh Elser)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/2ba4c4eb
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/2ba4c4eb
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/2ba4c4eb

Branch: refs/heads/master
Commit: 2ba4c4eb9fe568b962f9d71de829531f51c5375b
Parents: eb82b8b
Author: anoopsjohn <an...@gmail.com>
Authored: Tue Apr 21 17:34:09 2015 +0530
Committer: anoopsjohn <an...@gmail.com>
Committed: Tue Apr 21 17:34:09 2015 +0530

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/TagRewriteCell.java |  5 ++
 .../apache/hadoop/hbase/TestTagRewriteCell.java | 48 ++++++++++++++++++++
 2 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/2ba4c4eb/hbase-server/src/main/java/org/apache/hadoop/hbase/TagRewriteCell.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 313ecb8..eb6d3be 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;
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/2ba4c4eb/hbase-server/src/test/java/org/apache/hadoop/hbase/TestTagRewriteCell.java
----------------------------------------------------------------------
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 0000000..56cecf4
--- /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);
+  }
+}