THRIFT-100. java: Set __isset better in beans style
When setX(null) is called on a structure, set __isset.x to false.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@700667 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 37af482..4440928 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -1131,7 +1131,13 @@
indent_up();
indent(out) << "this." << field_name << " = " << field_name << ";" <<
endl;
- indent(out) << "this.__isset." << field_name << " = true;" << endl;
+ // if the type isn't nullable, then the setter can't have been an unset in disguise.
+ if ((type->is_base_type() && !type->is_string()) || type->is_enum() ) {
+ indent(out) << "this.__isset." << field_name << " = true;" << endl;
+ } else {
+ indent(out) << "this.__isset." << field_name << " = (" << field_name << " != null);" << endl;
+ }
+
indent_down();
indent(out) << "}" << endl << endl;