THRIFT-1008. java: byte[] accessors throw NPE on unset field
authorBryan Duxbury <bryanduxbury@apache.org>
Wed, 24 Nov 2010 21:30:00 +0000 (21:30 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Wed, 24 Nov 2010 21:30:00 +0000 (21:30 +0000)
This patch adds a null check to TBaseHelper.rightSize().

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1038833 13f79535-47bb-0310-9956-ffa450edef68

lib/java/src/org/apache/thrift/TBaseHelper.java
lib/java/test/org/apache/thrift/TestTBaseHelper.java

index 2837d0b..5898d5b 100644 (file)
@@ -270,6 +270,9 @@ public final class TBaseHelper {
   }
 
   public static ByteBuffer rightSize(ByteBuffer in) {
+    if (in == null) {
+      return null;
+    }
     if (wrapsFullArray(in)) {
       return in;
     }
index 6d72ad8..6378524 100644 (file)
@@ -151,6 +151,10 @@ public class TestTBaseHelper extends TestCase {
     assertEquals(ByteBuffer.wrap(b1, 1, 3), ByteBuffer.wrap(b3));
   }
 
+  public void testRightSize() throws Exception {
+    assertNull(TBaseHelper.rightSize(null));
+  }
+
   public void testCopyBinaryWithByteBuffer() throws Exception {
     byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5};
     ByteBuffer b = ByteBuffer.wrap(bytes);