Thrift 4556: Optional rethrow of unhandled exceptions in java processor (#1544)
Client: java
diff --git a/compiler/cpp/src/thrift/generate/t_java_generator.cc b/compiler/cpp/src/thrift/generate/t_java_generator.cc
index 4d81c98..2db3c3f 100644
--- a/compiler/cpp/src/thrift/generate/t_java_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_java_generator.cc
@@ -71,7 +71,7 @@
use_option_type_ = false;
undated_generated_annotations_ = false;
suppress_generated_annotations_ = false;
- handle_runtime_exceptions_ = false;
+ rethrow_unhandled_exceptions_ = false;
unsafe_binaries_ = false;
for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
if( iter->first.compare("beans") == 0) {
@@ -94,8 +94,8 @@
reuse_objects_ = true;
} else if( iter->first.compare("option_type") == 0) {
use_option_type_ = true;
- } else if( iter->first.compare("handle_runtime_exceptions") == 0) {
- handle_runtime_exceptions_ = true;
+ } else if( iter->first.compare("rethrow_unhandled_exceptions") == 0) {
+ rethrow_unhandled_exceptions_ = true;
} else if( iter->first.compare("generated_annotations") == 0) {
if( iter->second.compare("undated") == 0) {
undated_generated_annotations_ = true;
@@ -413,7 +413,7 @@
bool use_option_type_;
bool undated_generated_annotations_;
bool suppress_generated_annotations_;
- bool handle_runtime_exceptions_;
+ bool rethrow_unhandled_exceptions_;
bool unsafe_binaries_;
};
@@ -3634,8 +3634,8 @@
indent(f_service_) << "}" << endl << endl;
indent(f_service_) << "@Override" << endl;
- indent(f_service_) << "protected boolean handleRuntimeExceptions() {" << endl;
- indent(f_service_) << " return " << ((handle_runtime_exceptions_) ? "true" : "false") << ";" << endl;
+ indent(f_service_) << "protected boolean rethrowUnhandledExceptions() {" << endl;
+ indent(f_service_) << " return " << ((rethrow_unhandled_exceptions_) ? "true" : "false") << ";" << endl;
indent(f_service_) << "}" << endl << endl;
indent(f_service_) << "public " << resultname << " getResult(I iface, " << argsname
@@ -5428,9 +5428,9 @@
" android_legacy: Do not use java.io.IOException(throwable) (available for Android 2.3 and "
"above).\n"
" option_type: Wrap optional fields in an Option type.\n"
- " handle_runtime_exceptions:\n"
- " Send TApplicationException to the client when RuntimeException occurs on "
- "the server. (Default behavior is to close the connection instead.)\n"
+ " rethrow_unhandled_exceptions:\n"
+ " Enable rethrow of unhandled exceptions and let them propagate futher."
+ " (Default behavior is to catch and log it.)\n"
" java5: Generate Java 1.5 compliant code (includes android_legacy flag).\n"
" reuse-objects: Data objects will not be allocated, but existing instances will be used "
"(read and write).\n"
diff --git a/lib/java/src/org/apache/thrift/ProcessFunction.java b/lib/java/src/org/apache/thrift/ProcessFunction.java
index 340e301..be76aff 100644
--- a/lib/java/src/org/apache/thrift/ProcessFunction.java
+++ b/lib/java/src/org/apache/thrift/ProcessFunction.java
@@ -45,6 +45,7 @@
msgType = TMessageType.EXCEPTION;
} catch (Exception ex) {
LOGGER.error("Internal error processing " + getMethodName(), ex);
+ if(rethrowUnhandledExceptions()) throw new RuntimeException(ex);
if(!isOneway()) {
result = new TApplicationException(TApplicationException.INTERNAL_ERROR,
"Internal error processing " + getMethodName());
@@ -71,7 +72,7 @@
}
}
- protected boolean handleRuntimeExceptions() {
+ protected boolean rethrowUnhandledExceptions(){
return false;
}