THRIFT-218. java: When validation fails on serialization/deserialization, print out the invalid object
The error thrown when validation fails now contains the toString output.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@738764 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 3e718fb..e99583a 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -974,14 +974,14 @@
indent() << "iprot.readStructEnd();" << endl << endl;
// in non-beans style, check for required fields of primitive type
- // (which can be checked here but no in the general validate method)
+ // (which can be checked here but not in the general validate method)
if (!bean_style_){
out << endl << indent() << "// check for required fields of primitive type, which can't be checked in the validate method" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if ((*f_iter)->get_req() == t_field::T_REQUIRED && !type_can_be_null((*f_iter)->get_type())) {
out <<
indent() << "if (!__isset." << (*f_iter)->get_name() << ") {" << endl <<
- indent() << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' was not found in serialized data!\");" << endl <<
+ indent() << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' was not found in serialized data! Struct: \" + toString());" << endl <<
indent() << "}" << endl;
}
}
@@ -1012,12 +1012,12 @@
if (bean_style_) {
out <<
indent() << "if (!__isset." << (*f_iter)->get_name() << ") {" << endl <<
- indent() << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' is unset!\");" << endl <<
+ indent() << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' is unset! Struct:\" + toString());" << endl <<
indent() << "}" << endl << endl;
} else{
if (type_can_be_null((*f_iter)->get_type())) {
indent(out) << "if (" << (*f_iter)->get_name() << " == null) {" << endl;
- indent(out) << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' was not present!\");" << endl;
+ indent(out) << " throw new TProtocolException(\"Required field '" << (*f_iter)->get_name() << "' was not present! Struct: \" + toString());" << endl;
indent(out) << "}" << endl;
} else {
indent(out) << "// alas, we cannot check '" << (*f_iter)->get_name() << "' because it's a primitive and you chose the non-beans generator." << endl;