Author: bryanduxbury
Date: Wed Nov 24 21:30:00 2010
New Revision: 1038833

URL: http://svn.apache.org/viewvc?rev=1038833&view=rev
Log:
THRIFT-1008. java: byte[] accessors throw NPE on unset field

This patch adds a null check to TBaseHelper.rightSize().

Modified:
    thrift/trunk/lib/java/src/org/apache/thrift/TBaseHelper.java
    thrift/trunk/lib/java/test/org/apache/thrift/TestTBaseHelper.java

Modified: thrift/trunk/lib/java/src/org/apache/thrift/TBaseHelper.java
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/java/src/org/apache/thrift/TBaseHelper.java?rev=1038833&r1=1038832&r2=1038833&view=diff
==============================================================================
--- thrift/trunk/lib/java/src/org/apache/thrift/TBaseHelper.java (original)
+++ thrift/trunk/lib/java/src/org/apache/thrift/TBaseHelper.java Wed Nov 24 
21:30:00 2010
@@ -270,6 +270,9 @@ public final class TBaseHelper {
   }
 
   public static ByteBuffer rightSize(ByteBuffer in) {
+    if (in == null) {
+      return null;
+    }
     if (wrapsFullArray(in)) {
       return in;
     }

Modified: thrift/trunk/lib/java/test/org/apache/thrift/TestTBaseHelper.java
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/java/test/org/apache/thrift/TestTBaseHelper.java?rev=1038833&r1=1038832&r2=1038833&view=diff
==============================================================================
--- thrift/trunk/lib/java/test/org/apache/thrift/TestTBaseHelper.java (original)
+++ thrift/trunk/lib/java/test/org/apache/thrift/TestTBaseHelper.java Wed Nov 
24 21:30:00 2010
@@ -151,6 +151,10 @@ public class TestTBaseHelper extends Tes
     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);


Reply via email to