[ 
https://issues.apache.org/jira/browse/THRIFT-5519?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Kormukhin updated THRIFT-5519:
-----------------------------------
    Description: 
Exceptions thrown in void methods are lost on the client side when using an 
asynchronous Java client.

 

For non-void methods, generated getResult() looks like this:

 
{code:java}
public java.lang.String getResult() throws TExampleException, 
org.apache.thrift.TException {
  if (getState() != 
org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new java.lang.IllegalStateException("Method call not finished!");
  }
  org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
  org.apache.thrift.protocol.TProtocol prot = 
client.getProtocolFactory().getProtocol(memoryTransport);
  return (new Client(prot)).recv_returnString();
}
{code}
 

For void methods like:
{code:java}
public Void getResult() throws TExampleException, org.apache.thrift.TException {
  if (getState() != 
org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new java.lang.IllegalStateException("Method call not finished!");
  }
  org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
  org.apache.thrift.protocol.TProtocol prot = 
client.getProtocolFactory().getProtocol(memoryTransport);
  return null;
} {code}
There are no call to (new Client(prot)).recv_returnVoidThrows() here.

But in recv_returnVoidThrows():
{code:java}
public void recv_returnVoidThrows() throws TExampleException, 
org.apache.thrift.TException
{
  returnVoidThrows_result result = new returnVoidThrows_result();
  receiveBase(result, "returnVoidThrows");
  if (result.error != null) {
    throw result.error;
  }
  return;
} {code}
the received response is read and the received exceptions are thrown.

 

The correct getResult() for void methods should look like this:
{code:java}
public Void getResult() throws TExampleException, org.apache.thrift.TException {
  if (getState() != 
org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new java.lang.IllegalStateException("Method call not finished!");
  }
  org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
  org.apache.thrift.protocol.TProtocol prot = 
client.getProtocolFactory().getProtocol(memoryTransport);
  (new Client(prot)).recv_returnVoidThrows();
  return null;
} {code}
 

Attached test (bug-async-void-meths-lost-exception.zip) demonstrates this issue.

!2022-02-18_190339.png|width=838,height=452!

 

  was:
Exceptions thrown in void methods are lost on the client side when using an 
asynchronous Java client.

 

For non-void methods, generated getResult() looks like this:

 
{code:java}
public java.lang.String getResult() throws TExampleException, 
org.apache.thrift.TException {
  if (getState() != 
org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new java.lang.IllegalStateException("Method call not finished!");
  }
  org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
  org.apache.thrift.protocol.TProtocol prot = 
client.getProtocolFactory().getProtocol(memoryTransport);
  return (new Client(prot)).recv_returnString();
}
{code}
 

For void methods like:
{code:java}
public Void getResult() throws TExampleException, org.apache.thrift.TException {
  if (getState() != 
org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new java.lang.IllegalStateException("Method call not finished!");
  }
  org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
  org.apache.thrift.protocol.TProtocol prot = 
client.getProtocolFactory().getProtocol(memoryTransport);
  return null;
} {code}
There are no call to (new Client(prot)).recv_returnVoidThrows() here.

But in recv_returnVoidThrows():
{code:java}
public void recv_returnVoidThrows() throws TExampleException, 
org.apache.thrift.TException
{
  returnVoidThrows_result result = new returnVoidThrows_result();
  receiveBase(result, "returnVoidThrows");
  if (result.error != null) {
    throw result.error;
  }
  return;
} {code}
the received response is read and the received exceptions are thrown.

 

The correct getResult() for void methods should look like this:
{code:java}
public Void getResult() throws TExampleException, org.apache.thrift.TException {
  if (getState() != 
org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new java.lang.IllegalStateException("Method call not finished!");
  }
  org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
  org.apache.thrift.protocol.TProtocol prot = 
client.getProtocolFactory().getProtocol(memoryTransport);
  (new Client(prot)).recv_returnVoidThrows();
  return null;
} {code}
 

Attached test demonstrates this issue.

!2022-02-18_190339.png|width=838,height=452!

 


> Java async client loses exceptions in void methods
> --------------------------------------------------
>
>                 Key: THRIFT-5519
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5519
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler
>    Affects Versions: 0.11.0, 0.15.0, 0.16.0
>            Reporter: Alex Kormukhin
>            Priority: Major
>         Attachments: 2022-02-18_190339.png, 
> bug-async-void-meths-lost-exception.zip
>
>
> Exceptions thrown in void methods are lost on the client side when using an 
> asynchronous Java client.
>  
> For non-void methods, generated getResult() looks like this:
>  
> {code:java}
> public java.lang.String getResult() throws TExampleException, 
> org.apache.thrift.TException {
>   if (getState() != 
> org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
>     throw new java.lang.IllegalStateException("Method call not finished!");
>   }
>   org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
> org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
>   org.apache.thrift.protocol.TProtocol prot = 
> client.getProtocolFactory().getProtocol(memoryTransport);
>   return (new Client(prot)).recv_returnString();
> }
> {code}
>  
> For void methods like:
> {code:java}
> public Void getResult() throws TExampleException, 
> org.apache.thrift.TException {
>   if (getState() != 
> org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
>     throw new java.lang.IllegalStateException("Method call not finished!");
>   }
>   org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
> org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
>   org.apache.thrift.protocol.TProtocol prot = 
> client.getProtocolFactory().getProtocol(memoryTransport);
>   return null;
> } {code}
> There are no call to (new Client(prot)).recv_returnVoidThrows() here.
> But in recv_returnVoidThrows():
> {code:java}
> public void recv_returnVoidThrows() throws TExampleException, 
> org.apache.thrift.TException
> {
>   returnVoidThrows_result result = new returnVoidThrows_result();
>   receiveBase(result, "returnVoidThrows");
>   if (result.error != null) {
>     throw result.error;
>   }
>   return;
> } {code}
> the received response is read and the received exceptions are thrown.
>  
> The correct getResult() for void methods should look like this:
> {code:java}
> public Void getResult() throws TExampleException, 
> org.apache.thrift.TException {
>   if (getState() != 
> org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
>     throw new java.lang.IllegalStateException("Method call not finished!");
>   }
>   org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new 
> org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
>   org.apache.thrift.protocol.TProtocol prot = 
> client.getProtocolFactory().getProtocol(memoryTransport);
>   (new Client(prot)).recv_returnVoidThrows();
>   return null;
> } {code}
>  
> Attached test (bug-async-void-meths-lost-exception.zip) demonstrates this 
> issue.
> !2022-02-18_190339.png|width=838,height=452!
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to