THRIFT-278. java: #validate exceptions should contain the offending value
authorBryan Duxbury <bryanduxbury@apache.org>
Wed, 18 Mar 2009 01:50:50 +0000 (01:50 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Wed, 18 Mar 2009 01:50:50 +0000 (01:50 +0000)
This patch causes validate to throw exceptions that contain the bad field value as well as the field name. I had to modify it slightly from the patch on the issue to conform with the new style isset checks.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@755454 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_java_generator.cc

index abbba8b..442488e 100644 (file)
@@ -1043,9 +1043,9 @@ void t_java_generator::generate_java_validator(ofstream& out,
         package = program->get_namespace("java") + ".";
       }
 
-      indent(out) << "if (__isset." << field->get_name() << " && !" << package << type->get_name() << ".VALID_VALUES.contains(" << field->get_name() << ")){" << endl;
+      indent(out) << "if (" << generate_isset_check(field) << " && !" << package << type->get_name() << ".VALID_VALUES.contains(" << field->get_name() << ")){" << endl;
       indent_up();
-      indent(out) << "throw new TProtocolException(\"Invalid value of field '" << field->get_name() << "'!\");" << endl;
+      indent(out) << "throw new TProtocolException(\"The field '" << field->get_name() << "' has been assigned the invalid value \" + " << field->get_name() << ");" << endl;
       indent_down();
       indent(out) << "}" << endl;
     }