Author: bryanduxbury
Date: Thu Jan 29 05:38:10 2009
New Revision: 738764

URL: http://svn.apache.org/viewvc?rev=738764&view=rev
Log:
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.

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc

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=738764&r1=738763&r2=738764&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 Thu 
Jan 29 05:38:10 2009
@@ -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;


Reply via email to