THRIFT-368. java: setFieldValue should allow nulls for all field types
After this patch, setFieldValue will treat a set with a null as an unset.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@753337 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 943878f..abbba8b 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -1194,8 +1194,11 @@
void t_java_generator::generate_reflection_setters(ostringstream& out, t_type* type, string field_name, string cap_name) {
indent(out) << "case " << upcase_string(field_name) << ":" << endl;
indent_up();
-
- indent(out) << "set" << cap_name << "((" << type_name(type, true, false) << ")value);" << endl;
+ indent(out) << "if (value == null) {" << endl;
+ indent(out) << " unset" << get_cap_name(field_name) << "();" << endl;
+ indent(out) << "} else {" << endl;
+ indent(out) << " set" << cap_name << "((" << type_name(type, true, false) << ")value);" << endl;
+ indent(out) << "}" << endl;
indent(out) << "break;" << endl << endl;
indent_down();