You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2011/10/05 02:04:32 UTC

svn commit: r1179013 - in /hbase/branches/0.92: CHANGES.txt src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java src/test/java/org/apache/hadoop/hbase/avro/TestAvroUtil.java

Author: stack
Date: Wed Oct  5 00:04:31 2011
New Revision: 1179013

URL: http://svn.apache.org/viewvc?rev=1179013&view=rev
Log:
HBASE-4494 AvroServer:: get fails with NPE on a non-existent row

Added:
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/avro/TestAvroUtil.java
Modified:
    hbase/branches/0.92/CHANGES.txt
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java

Modified: hbase/branches/0.92/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/CHANGES.txt?rev=1179013&r1=1179012&r2=1179013&view=diff
==============================================================================
--- hbase/branches/0.92/CHANGES.txt (original)
+++ hbase/branches/0.92/CHANGES.txt Wed Oct  5 00:04:31 2011
@@ -319,7 +319,9 @@ Release 0.92.0 - Unreleased
    HBASE-4496  HFile V2 does not honor setCacheBlocks when scanning (Lars and Mikhail)
    HBASE-4531  hbase-4454 failsafe broke mvn site; back it out or fix
                (Akash Ashok)
-   HBASE-4334 HRegion.get never validates row (Lars Hofhansl)
+   HBASE-4334  HRegion.get never validates row (Lars Hofhansl)
+   HBASE-4494  AvroServer:: get fails with NPE on a non-existent row 
+               (Kay Kay)
 
   TESTS
    HBASE-4492  TestRollingRestart fails intermittently

Modified: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java?rev=1179013&r1=1179012&r2=1179013&view=diff
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java (original)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/avro/AvroUtil.java Wed Oct  5 00:04:31 2011
@@ -302,7 +302,8 @@ public class AvroUtil {
   // TODO(hammer): Pick one: Timestamp or TimeStamp
   static public AResult resultToAResult(Result result) {
     AResult aresult = new AResult();
-    aresult.row = ByteBuffer.wrap(result.getRow());
+    byte[] row = result.getRow();
+    aresult.row = ByteBuffer.wrap(row != null ? row : new byte[1]);
     Schema s = Schema.createArray(AResultEntry.SCHEMA$);
     GenericData.Array<AResultEntry> entries = null;
     List<KeyValue> resultKeyValues = result.list();

Added: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/avro/TestAvroUtil.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/avro/TestAvroUtil.java?rev=1179013&view=auto
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/avro/TestAvroUtil.java (added)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/avro/TestAvroUtil.java Wed Oct  5 00:04:31 2011
@@ -0,0 +1,40 @@
+/** 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.avro;
+
+
+import org.apache.hadoop.hbase.avro.generated.AResult;
+import org.apache.hadoop.hbase.client.Result;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestAvroUtil {
+
+  
+  @Test
+  public void testGetEmpty() {
+    Result result = Mockito.mock(Result.class);
+    Mockito.when(result.getRow()).thenReturn(null);
+    //Get on a row, that does not exist, returns a result, 
+    //whose row is null.
+    AResult aresult = AvroUtil.resultToAResult(result);
+    Assert.assertNotNull(aresult);
+  }
+
+}