You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Mehdi Salarkia (JIRA)" <ji...@apache.org> on 2018/03/01 02:54:00 UTC

[jira] [Created] (THRIFT-4501) Java client hides server side exceptions

Mehdi Salarkia created THRIFT-4501:
--------------------------------------

             Summary: Java client hides server side exceptions 
                 Key: THRIFT-4501
                 URL: https://issues.apache.org/jira/browse/THRIFT-4501
             Project: Thrift
          Issue Type: Bug
          Components: Java - Library
    Affects Versions: 0.11.0
            Reporter: Mehdi Salarkia


In my thrift definition I have some void methods that may through exceptions. When I generate my java client with my thrift definition it seems like there is a bug in the generated code that does not throw the RuntimeException that was thrown by the server in the client.
However this works fine for non void functions. When I looked at the generated codes for non-void functions seems like there is a call to `recv_${method_name}` that will check if the error occurred on the server side, it will re-throw on the client side but for the void method it simply returns null.
After making the following change everything looks to be working. 
```
--- a/compiler/cpp/src/thrift/generate/t_java_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_java_generator.cc
@@ -3177,7 +3177,8 @@ void t_java_generator::generate_service_async_client(t_service* tservice) {
 "client.getProtocolFactory().getProtocol(memoryTransport);" << endl;
 indent(f_service_);
 if (ret_type->is_void()) { // NB: Includes oneways which always return void.
- f_service_ << "return null;" << endl;
+ f_service_ << "(new Client(prot)).recv" + sep + javaname + "();"<< endl;
+ indent(f_service_) << "return null;" << endl;
 } else {
 f_service_ << "return (new Client(prot)).recv" + sep + javaname + "();" << endl;
 }
```
I don't have the commit permission yet but I will create a pull request after your confirmation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)