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..7845c12 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,15 @@ public class Result implements CellScannable, CellScanner { /** * Copy another Result into this one. Needed for the old Mapred framework + * @throws UnsupportedOperationException if invoked on instance of EMPTY_RESULT + * (which is supposed to be immutable). * @param other */ public void copyFrom(Result other) { + if (this == EMPTY_RESULT) { + throw new UnsupportedOperationException("Invoking #copyFrom() on" + + " EMPTY_RESULT isn't allowed!"); + } this.row = null; this.familyMap = null; this.cells = other.cells; @@ -903,4 +909,4 @@ public class Result implements CellScannable, CellScanner { public ClientProtos.RegionLoadStats getStats() { return stats; } -} \ No newline at end of file +} 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..e751997 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 (UnsupportedOperationException ex) { + LOG.debug("As expected: " + ex.getMessage()); + } + } /** * Microbenchmark that compares {@link Result#getValue} and {@link Result#loadValue} performance.