Author: bryanduxbury
Date: Sun Feb 28 05:19:38 2010
New Revision: 917130

URL: http://svn.apache.org/viewvc?rev=917130&view=rev
Log:
THRIFT-716. java: Field names can conflict with local variables in code for 
unions

This patch resolves the name clash issue by removing the unnecessary parameters 
from the generated method and using the protected variables directly instead.

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
    incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc?rev=917130&r1=917129&r2=917130&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc 
(original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc Sun 
Feb 28 05:19:38 2010
@@ -915,11 +915,11 @@
 
 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 @@
     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;

Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java?rev=917130&r1=917129&r2=917130&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java (original)
+++ incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java Sun Feb 
28 05:19:38 2010
@@ -163,7 +163,7 @@
     }
     oprot.writeStructBegin(getStructDesc());
     oprot.writeFieldBegin(getFieldDesc(setField_));
-    writeValue(oprot, setField_, value_);
+    writeValue(oprot);
     oprot.writeFieldEnd();
     oprot.writeFieldStop();
     oprot.writeStructEnd();
@@ -185,7 +185,7 @@
    */
   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();
 


Reply via email to