You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jk...@apache.org on 2018/05/01 13:07:53 UTC

[thrift] branch master updated: Thrift 4556: Optional rethrow of unhandled exceptions in java processor (#1544)

This is an automated email from the ASF dual-hosted git repository.

jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new c7aa68b  Thrift 4556: Optional rethrow of unhandled exceptions in java processor (#1544)
c7aa68b is described below

commit c7aa68bd59d1d3a1bbcb133fc986ff404d47b129
Author: nicaro <ni...@gmail.com>
AuthorDate: Tue May 1 15:07:50 2018 +0200

    Thrift 4556: Optional rethrow of unhandled exceptions in java processor (#1544)
    
    Client: java
---
 compiler/cpp/src/thrift/generate/t_java_generator.cc | 18 +++++++++---------
 lib/java/src/org/apache/thrift/ProcessFunction.java  |  3 ++-
 2 files changed, 11 insertions(+), 10 deletions(-)

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 @@ public:
     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 @@ public:
         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 @@ private:
   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 @@ void t_java_generator::generate_process_function(t_service* tservice, t_function
   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 @@ THRIFT_REGISTER_GENERATOR(
     "    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 @@ public abstract class ProcessFunction<I, T extends TBase> {
       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 @@ public abstract class ProcessFunction<I, T extends TBase> {
     }
   }
 
-  protected boolean handleRuntimeExceptions() {
+  protected boolean rethrowUnhandledExceptions(){
     return false;
   }
 

-- 
To stop receiving notification emails like this one, please contact
jking@apache.org.