THRIFT-364. java: Use of enums in other namespaces breaks java generated code
This patch checks for different namespaces and prefixes appropriately.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@752696 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 f6038d6..943878f 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -1034,10 +1034,16 @@
out << indent() << "// check that fields of type enum have valid values" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = (*f_iter);
-
+ t_type* type = field->get_type();
// if field is an enum, check that its value is valid
- if (field->get_type()->is_enum()){
- indent(out) << "if (__isset." << field->get_name() << " && !" << field->get_type()->get_name() << ".VALID_VALUES.contains(" << field->get_name() << ")){" << endl;
+ if (type->is_enum()){
+ string package = "";
+ t_program* program = type->get_program();
+ if (program != NULL && program != program_) {
+ package = program->get_namespace("java") + ".";
+ }
+
+ indent(out) << "if (__isset." << field->get_name() << " && !" << 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_down();