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

Generated java service code emits a few dead local stores

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Trivial
    • Resolution: Unresolved
    • 0.10.0
    • None
    • Java - Compiler
    • None

    Description

      I created a simple service:

      namespace java org.apache.thrift.test
      
      service DeadLocalStore
      {
          void doNothing();
      }
      

      I compiled it with thrift --gen java. The resulting generated code has some dead local stores that are unnecessary:

          public static class doNothing_call extends org.apache.thrift.async.TAsyncMethodCall<Void> {
            public doNothing_call(org.apache.thrift.async.AsyncMethodCallback<Void> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
              super(client, protocolFactory, transport, resultHandler, false);
            }
      
            public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
              prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("doNothing", org.apache.thrift.protocol.TMessageType.CALL, 0));
              doNothing_args args = new doNothing_args();
              args.write(prot);
              prot.writeMessageEnd();
            }
      
            public Void getResult() throws 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;
            }
          }
      

      Above, memoryTransport and prot are unnecessary.

          private static class doNothing_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme<doNothing_args> {
      
            @Override
            public void write(org.apache.thrift.protocol.TProtocol prot, doNothing_args struct) throws org.apache.thrift.TException {
              org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
            }
      
            @Override
            public void read(org.apache.thrift.protocol.TProtocol prot, doNothing_args struct) throws org.apache.thrift.TException {
              org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
            }
          }
      

      Above, iprot and oprot are unnecessary.

                public void onError(java.lang.Exception e) {
                  byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
                  org.apache.thrift.TSerializable msg;
                  doNothing_result result = new doNothing_result();
                  if (e instanceof org.apache.thrift.transport.TTransportException) {
                    _LOGGER.error("TTransportException inside handler", e);
                    fb.close();
                    return;
                  } else if (e instanceof org.apache.thrift.TApplicationException) {
                    _LOGGER.error("TApplicationException inside handler", e);
                    msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
                    msg = (org.apache.thrift.TApplicationException)e;
                  } else {
                    _LOGGER.error("Exception inside handler", e);
                    msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
                    msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
                  }
                  try {
                    fcall.sendResponse(fb,msg,msgType,seqid);
                  } catch (java.lang.Exception ex) {
                    _LOGGER.error("Exception writing to internal frame buffer", ex);
                    fb.close();
                  }
                }
      

      Above, result is unnecessary.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            jking3 James E. King III

            Dates

              Created:
              Updated:

              Slack

                Issue deployment