diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java index 2cc38bf..7c49445 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java @@ -834,9 +834,14 @@ public class Result implements CellScannable, CellScanner { /** * Copy another Result into this one. Needed for the old Mapred framework + * @throws IllegalStateException if invoked on instance of EMPTY_RESULT + * (which is supposed to be immutable). * @param other */ public void copyFrom(Result other) { + if (this.equals(EMPTY_RESULT)) { + throw new IllegalStateException("Invoking #copyFrom() on EMPTY_RESULT isn't allowed!"); + } this.row = null; this.familyMap = null; this.cells = other.cells; diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java index fd4b01a..b2f70d6 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java @@ -229,6 +229,20 @@ public class TestResult extends TestCase { } } + /** + * Verifies that one can't call copyFrom on instance of EMPTY_RESULT. + */ + public void testCopyFromOnEmptyResult() { + try { + Result emptyResult = Result.EMPTY_RESULT; + Result otherResult = new Result(); + emptyResult.copyFrom(otherResult); + fail("IllegalStateException should have been thrown when trying to" + + "call copyFrom on EMPTY_RESULT!"); + } catch (RuntimeException ex) { + assertTrue(ex instanceof IllegalStateException); + } + } /** * Microbenchmark that compares {@link Result#getValue} and {@link Result#loadValue} performance.