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 bff50338ba5f..eb72ef82995f 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 @@ -913,7 +913,7 @@ public CellScanner cellScanner() { @Override public Cell current() { - if (cells == null + if (isEmpty() || cellScannerIndex == INITIAL_CELLSCANNER_INDEX || cellScannerIndex >= cells.length) return null; @@ -922,7 +922,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; 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 e763aa6689c3..5d9566b6344d 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 @@ -132,14 +132,12 @@ public void testCurrentOnEmptyCell() throws IOException { } @Test - public void testAdvanceTwiceOnEmptyCell() throws IOException { + public void testAdvanceMultipleOnEmptyCell() 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()); + // 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()); } }