THRIFT-2974 fix optional writeToParcel
Client: Java
Patch: Max Spencer
This closes #687
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index 9da52d1..733852f 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -1634,7 +1634,7 @@
} else if (type_name(t) == "float") {
indent(out) << "out.writeFloat(" << name << ");" << endl;
} else if (t->is_enum()) {
- indent(out) << "out.writeInt(" << name << ".getValue());" << endl;
+ indent(out) << "out.writeInt(" << name << " != null ? " << name << ".getValue() : -1);" << endl;
} else if (t->is_list()) {
if (((t_list*)t)->get_elem_type()->get_true_type()->is_struct()) {
indent(out) << "out.writeTypedList(" << name << ");" << endl;