From 0e83d7445db057476a2ac3263ba61f9f540bfcae Mon Sep 17 00:00:00 2001 From: Nicolas Spiegelberg Date: Fri, 28 Oct 2011 03:29:52 +0000 Subject: [PATCH] HBASE-4679 Thrift null mutation error git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1190143 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../apache/hadoop/hbase/thrift/ThriftServer.java | 16 ++++++++++++---- .../hadoop/hbase/thrift/TestThriftServer.java | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2ee1391d2e7..94b8f95de51 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -414,6 +414,7 @@ Release 0.92.0 - Unreleased of ArithmeticException: / by zero. HBASE-4300 Start of new-version master fails if old master's znode is hanging around + HBASE-4679 Thrift null mutation error TESTS HBASE-4450 test for number of blocks read: to serve as baseline for expected diff --git a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java index b8140a1d090..a46aceec409 100644 --- a/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java +++ b/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java @@ -597,9 +597,13 @@ public class ThriftServer { } } else { if(famAndQf.length == 1) { - put.add(famAndQf[0], new byte[0], getBytes(m.value)); + put.add(famAndQf[0], HConstants.EMPTY_BYTE_ARRAY, + m.value != null ? m.value.array() + : HConstants.EMPTY_BYTE_ARRAY); } else { - put.add(famAndQf[0], famAndQf[1], getBytes(m.value)); + put.add(famAndQf[0], famAndQf[1], + m.value != null ? m.value.array() + : HConstants.EMPTY_BYTE_ARRAY); } } } @@ -642,9 +646,13 @@ public class ThriftServer { } } else { if(famAndQf.length == 1) { - put.add(famAndQf[0], new byte[0], getBytes(m.value)); + put.add(famAndQf[0], HConstants.EMPTY_BYTE_ARRAY, + m.value != null ? m.value.array() + : HConstants.EMPTY_BYTE_ARRAY); } else { - put.add(famAndQf[0], famAndQf[1], getBytes(m.value)); + put.add(famAndQf[0], famAndQf[1], + m.value != null ? m.value.array() + : HConstants.EMPTY_BYTE_ARRAY); } } } diff --git a/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java b/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java index a760644a010..42c967a32a5 100644 --- a/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java +++ b/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java @@ -179,6 +179,14 @@ public class TestThriftServer { size = handler.getRow(tableAname, rowBname).size(); assertEquals(0, size); + // Try null mutation + List mutations = new ArrayList(); + mutations.add(new Mutation(false, columnAname, null)); + handler.mutateRow(tableAname, rowAname, mutations); + TRowResult rowResult3 = handler.getRow(tableAname, rowAname).get(0); + assertEquals(rowAname, rowResult3.row); + assertEquals(0, rowResult3.columns.get(columnAname).value.array().length); + // Teardown handler.disableTable(tableAname); handler.deleteTable(tableAname);