THRIFT-716. java: Field names can conflict with local variables in code for unions
authorBryan Duxbury <bryanduxbury@apache.org>
Sun, 28 Feb 2010 05:19:38 +0000 (05:19 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Sun, 28 Feb 2010 05:19:38 +0000 (05:19 +0000)
This patch resolves the name clash issue by removing the unnecessary parameters from the generated method and using the protected variables directly instead.

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

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

index 949d062..e28a214 100644 (file)
@@ -915,11 +915,11 @@ void t_java_generator::generate_read_value(ofstream& out, t_struct* tstruct) {
 
 void t_java_generator::generate_write_value(ofstream& out, t_struct* tstruct) {
   indent(out) << "@Override" << endl;
-  indent(out) << "protected void writeValue(TProtocol oprot, _Fields setField, Object value) throws TException {" << endl;
+  indent(out) << "protected void writeValue(TProtocol oprot) throws TException {" << endl;
 
   indent_up();
 
-  indent(out) << "switch (setField) {" << endl;
+  indent(out) << "switch (setField_) {" << endl;
   indent_up();
 
   const vector<t_field*>& members = tstruct->get_members();
@@ -931,14 +931,14 @@ void t_java_generator::generate_write_value(ofstream& out, t_struct* tstruct) {
     indent(out) << "case " << constant_name(field->get_name()) << ":" << endl;
     indent_up();
     indent(out) << type_name(field->get_type(), true, false) << " " << field->get_name() 
-      << " = (" <<  type_name(field->get_type(), true, false) << ")getFieldValue();" << endl;
+      << " = (" <<  type_name(field->get_type(), true, false) << ")value_;" << endl;
     generate_serialize_field(out, field, "");
     indent(out) << "return;" << endl;
     indent_down();
   }
   
   indent(out) << "default:" << endl;
-  indent(out) << "  throw new IllegalStateException(\"Cannot write union with unknown field \" + setField);" << endl;
+  indent(out) << "  throw new IllegalStateException(\"Cannot write union with unknown field \" + setField_);" << endl;
 
   indent_down();
   indent(out) << "}" << endl;
index 625b00d..cc3c069 100644 (file)
@@ -163,7 +163,7 @@ public abstract class TUnion<F extends TFieldIdEnum> implements TBase<F> {
     }
     oprot.writeStructBegin(getStructDesc());
     oprot.writeFieldBegin(getFieldDesc(setField_));
-    writeValue(oprot, setField_, value_);
+    writeValue(oprot);
     oprot.writeFieldEnd();
     oprot.writeFieldStop();
     oprot.writeStructEnd();
@@ -185,7 +185,7 @@ public abstract class TUnion<F extends TFieldIdEnum> implements TBase<F> {
    */
   protected abstract Object readValue(TProtocol iprot, TField field) throws TException;
 
-  protected abstract void writeValue(TProtocol oprot, F setField, Object value) throws TException;
+  protected abstract void writeValue(TProtocol oprot) throws TException;
 
   protected abstract TStruct getStructDesc();