THRIFT-1146 add java:android_legacy option to the compiler
Issue: Android Incompatibility : in Android < 2.3 java.io.IOException doesn't support for Throwable parameter in constructor
Patch: Alessandro Rossi
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1094044 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 3fa9b16..e453249 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -59,6 +59,9 @@
iter = parsed_options.find("hashcode");
gen_hash_code_ = (iter != parsed_options.end());
+ iter = parsed_options.find("android_legacy");
+ android_legacy_ = (iter != parsed_options.end());
+
out_dir_base_ = (bean_style_ ? "gen-javabean" : "gen-java");
}
@@ -258,6 +261,7 @@
bool private_members_;
bool nocamel_style_;
bool gen_hash_code_;
+ bool android_legacy_;
};
@@ -3839,7 +3843,7 @@
indent(out) << " try {" << endl;
indent(out) << " write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));" << endl;
indent(out) << " } catch (org.apache.thrift.TException te) {" << endl;
- indent(out) << " throw new java.io.IOException(te);" << endl;
+ indent(out) << " throw new java.io.IOException(te" << (android_legacy_? ".getMessage()" : "") << ");" << endl;
indent(out) << " }" << endl;
indent(out) << "}" << endl << endl;
}
@@ -3854,7 +3858,7 @@
}
indent(out) << " read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));" << endl;
indent(out) << " } catch (org.apache.thrift.TException te) {" << endl;
- indent(out) << " throw new java.io.IOException(te);" << endl;
+ indent(out) << " throw new java.io.IOException(te" << (android_legacy_? ".getMessage()" : "") << ");" << endl;
indent(out) << " }" << endl;
indent(out) << "}" << endl << endl;
}
@@ -3864,5 +3868,6 @@
" private-members: Members will be private, but setter methods will return 'this' like usual.\n"
" nocamel: Do not use CamelCase field accessors with beans.\n"
" hashcode: Generate quality hashCode methods.\n"
+" android_legacy: Do not use java.io.IOException(throwable) (available for Android 2.3 and above).\n"
)