From: Bryan Duxbury Date: Sun, 28 Feb 2010 05:19:38 +0000 (+0000) Subject: THRIFT-716. java: Field names can conflict with local variables in code for unions X-Git-Tag: 0.3.0~109 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=4e7cf25b9574eb439b329070fd57e854948144df;p=common%2Fthrift.git 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. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@917130 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index 949d0628..e28a2141 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -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& 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; diff --git a/lib/java/src/org/apache/thrift/TUnion.java b/lib/java/src/org/apache/thrift/TUnion.java index 625b00d9..cc3c069d 100644 --- a/lib/java/src/org/apache/thrift/TUnion.java +++ b/lib/java/src/org/apache/thrift/TUnion.java @@ -163,7 +163,7 @@ public abstract class TUnion implements TBase { } 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 implements TBase { */ 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();