From aa64306b44e24a84b52d2e6f87dcb1fd4f5f5196 Mon Sep 17 00:00:00 2001 From: Yutong Sean Date: Tue, 25 Jan 2022 16:15:23 +0800 Subject: [PATCH 1/3] HBASE-26705 Backport HBASE-26688 to branch-1 --- .../main/java/org/apache/hadoop/hbase/client/Result.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 aaf7abfde006..99ac9da819a4 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 @@ -966,7 +966,7 @@ public CellScanner cellScanner() { @Override public Cell current() { - if (cells == null + if (isEmpty() || cellScannerIndex == INITIAL_CELLSCANNER_INDEX || cellScannerIndex >= cells.length) return null; @@ -975,7 +975,9 @@ public Cell current() { @Override public boolean advance() { - if (cells == null) return false; + if (isEmpty()) { + return false; + } cellScannerIndex++; if (cellScannerIndex < this.cells.length) { return true; From 9f864f556a747e741629cd59a4e7f0ac4ee4519e Mon Sep 17 00:00:00 2001 From: Yutong Sean Date: Thu, 27 Jan 2022 16:28:08 +0800 Subject: [PATCH 2/3] Remove TestResult#testAdvanceTwiceOnEmptyCell --- .../org/apache/hadoop/hbase/client/TestResult.java | 11 ----------- 1 file changed, 11 deletions(-) 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 418b0fb5e16a..80177ac1d258 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 @@ -115,17 +115,6 @@ public void testCurrentOnEmptyCell() throws IOException { 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); From 0bee00030524ce290ae3dd36326b478dfe1d5ad4 Mon Sep 17 00:00:00 2001 From: Yutong Sean Date: Mon, 21 Feb 2022 09:16:05 +0800 Subject: [PATCH 3/3] Added unit test --- .../java/org/apache/hadoop/hbase/client/TestResult.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 80177ac1d258..aaac70b71ab5 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 @@ -115,6 +115,15 @@ public void testCurrentOnEmptyCell() throws IOException { assertNull(r.current()); } + public void testAdvanceMultipleOnEmptyCell() throws IOException { + Result r = Result.create(new Cell[0]); + // After HBASE-26688, advance of result with empty cell list will always return false. + // Here 10 is an arbitrary number to test the logic. + for (int i = 0; i < 10; i++) { + assertFalse(r.advance()); + } + } + public void testMultiVersionGetColumn() throws Exception { KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100);