hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chia7...@apache.org
Subject hbase git commit: HBASE-18921 Fix Result.current ArrayIndexOutOfBoundsException
Date Sat, 07 Oct 2017 19:22:01 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.2 66205be06 -> 088882051


HBASE-18921 Fix Result.current ArrayIndexOutOfBoundsException

Patch ArrayIndexOutOfBoundsException when current() is called after
advance() has already returned false

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>


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

Branch: refs/heads/branch-1.2
Commit: 08888205109c0d15daa781d5eb4380a657ad34c5
Parents: 66205be
Author: Maytee Chinavanichkit <maytee.chinavanichkit@linecorp.com>
Authored: Mon Oct 2 15:19:25 2017 +0900
Committer: Chia-Ping Tsai <chia7712@gmail.com>
Committed: Sun Oct 8 03:08:38 2017 +0800

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Result.java    | 16 +++++++++++++---
 .../apache/hadoop/hbase/client/TestResult.java    | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/08888205/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java
index e764c4e..43648bb 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java
@@ -28,6 +28,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableMap;
+import java.util.NoSuchElementException;
 import java.util.TreeMap;
 
 import org.apache.hadoop.hbase.Cell;
@@ -944,14 +945,23 @@ public class Result implements CellScannable, CellScanner {
 
   @Override
   public Cell current() {
-    if (cells == null) return null;
-    return (cellScannerIndex < 0)? null: this.cells[cellScannerIndex];
+    if (cells == null
+            || cellScannerIndex == INITIAL_CELLSCANNER_INDEX
+            || cellScannerIndex >= cells.length)
+      return null;
+    return this.cells[cellScannerIndex];
   }
 
   @Override
   public boolean advance() {
     if (cells == null) return false;
-    return ++cellScannerIndex < this.cells.length;
+    cellScannerIndex++;
+    if (cellScannerIndex < this.cells.length) {
+      return true;
+    } else if (cellScannerIndex == this.cells.length) {
+      return false;
+    }
+    throw new NoSuchElementException("Cannot advance beyond the last cell");
   }
 
   public Boolean getExists() {

http://git-wip-us.apache.org/repos/asf/hbase/blob/08888205/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java
index d9496b3..5e73be3 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import junit.framework.TestCase;
 
@@ -105,6 +106,23 @@ public class TestResult extends TestCase {
     }
   }
 
+  public void testCurrentOnEmptyCell() throws IOException {
+    Result r = Result.create(new Cell[0]);
+    assertFalse(r.advance());
+    assertNull(r.current());
+  }
+
+  public void testAdvanceTwiceOnEmptyCell() throws IOException {
+    Result r = Result.create(new Cell[0]);
+    assertFalse(r.advance());
+    try {
+      r.advance();
+      fail("NoSuchElementException should have been thrown!");
+    } catch (NoSuchElementException ex) {
+      LOG.debug("As expected: " + ex.getMessage());
+    }
+  }
+
   public void testMultiVersionGetColumn() throws Exception {
     KeyValue [] kvs1 = genKVs(row, family, value, 1, 100);
     KeyValue [] kvs2 = genKVs(row, family, value, 200, 100);


Mime
View raw message