THRIFT-1319. java: Mismatch between how a union reads and writes a container
authorBryan Duxbury <bryanduxbury@apache.org>
Thu, 1 Sep 2011 18:54:07 +0000 (18:54 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Thu, 1 Sep 2011 18:54:07 +0000 (18:54 +0000)
This patch fixes the problem in the java generator (and removes an unnecessary comment). It also amends TestTUnion to catch this.

Patch: Armaan Sarkar

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

compiler/cpp/src/generate/t_java_generator.cc
lib/java/test/org/apache/thrift/TestTUnion.java

index 946400b..db33e93 100644 (file)
@@ -773,10 +773,6 @@ void t_java_generator::generate_java_union(t_struct* tstruct) {
 
   f_struct << endl;
 
-  //  generate_java_struct_standard_scheme(f_struct, tstruct);
-
-  f_struct << endl;
-
   scope_down(f_struct);
 
   f_struct.close();
@@ -1028,7 +1024,7 @@ void t_java_generator::generate_write_value(ofstream& out, t_struct* tstruct) {
     indent_up();
     indent(out) << type_name(field->get_type(), true, false) << " " << field->get_name() 
       << " = (" <<  type_name(field->get_type(), true, false) << ")value_;" << endl;
-    generate_serialize_field(out, field, "", false);
+    generate_serialize_field(out, field, "");
     indent(out) << "return;" << endl;
     indent_down();
   }
index b3d2968..e9d9825 100644 (file)
@@ -24,6 +24,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -152,6 +153,7 @@ public class TestTUnion extends TestCase {
 
   public void testSerialization() throws Exception {
     TestUnion union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);
+    union.setI32_set(Collections.singleton(42));
 
     TMemoryBuffer buf = new TMemoryBuffer(0);
     TProtocol proto = new TBinaryProtocol(buf);