From: Bryan Duxbury Date: Thu, 1 Mar 2012 23:41:09 +0000 (+0000) Subject: THRIFT-1529. java: TupleProtocol can unintentionally include an extra byte in bit... X-Git-Tag: 0.9.1~432 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=38087708b5ca5a575bb3bcbbf3c24ab181e1cfc1;p=common%2Fthrift.git THRIFT-1529. java: TupleProtocol can unintentionally include an extra byte in bit vectors when number of optional fields is an integral of 8 This patch harmonizes the math between writeBitSet and readBitSet to eliminate the mismatch in number of bytes calculation, allowing structs to be serialized correctly. git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1295995 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java b/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java index 14d50a6e..74f5226c 100644 --- a/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java +++ b/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java @@ -86,7 +86,7 @@ public final class TTupleProtocol extends TCompactProtocol { * @return a byte array of at least length 1 */ public static byte[] toByteArray(BitSet bits, int vectorWidth) { - byte[] bytes = new byte[vectorWidth / 8 + 1]; + byte[] bytes = new byte[(int) Math.ceil(vectorWidth/8.0)]; for (int i = 0; i < bits.length(); i++) { if (bits.get(i)) { bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8);