Alex Kormukhin created THRIFT-5519:
--------------------------------------
Summary: 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.16.0, 0.15.0, 0.11.0
Reporter: Alex Kormukhin
Attachments: 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 demonstrates this issue.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)