Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5519

Java async client loses exceptions in void methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.11.0, 0.15.0, 0.16.0
    • 0.17.0
    • Java - Compiler
    • None

    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:

       

      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();
      }
      

       

      For void methods like:

      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;
      } 

      There are no call to (new Client(prot)).recv_returnVoidThrows() here.

      But in recv_returnVoidThrows():

      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;
      } 

      the received response is read and the received exceptions are thrown.

       

      The correct getResult() for void methods should look like this:

      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;
      } 

       

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

       

      Attachments

        1. 2022-02-18_190339.png
          398 kB
          Alex Kormukhin
        2. bug-async-void-meths-lost-exception.zip
          21 kB
          Alex Kormukhin

        Issue Links

          Activity

            People

              Alex Kormukhin Alex Kormukhin
              Alex Kormukhin Alex Kormukhin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2.5h
                  2.5h