[ 
https://issues.apache.org/jira/browse/THRIFT-3533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15109649#comment-15109649
 ] 

Chris Bannister commented on THRIFT-3533:
-----------------------------------------

Yeah that is a bit of a pain, I think that comes down to the *Args structs 
being written out using the same code paths as user defined structs. The 
internal Args struct will obviously not be nil, so this could be optimised 
away. This change makes most sense when you look at user defined structs, for 
example the {{Lock}}

{{noformat}}
func (p *Lock) writeField1(oprot thrift.TProtocol) (err error) {
        if p.IsSetKey() {
                if err := oprot.WriteFieldBegin("key", thrift.STRUCT, 1); err 
!= nil {
                        return thrift.PrependError(fmt.Sprintf("%T write field 
begin error 1:key: ", p), err)
                }
                if err := p.Key.Write(oprot); err != nil {
                        return thrift.PrependError(fmt.Sprintf("%T error 
writing struct: ", p.Key), err)
                }
                if err := oprot.WriteFieldEnd(); err != nil {
                        return thrift.PrependError(fmt.Sprintf("%T write field 
end error 1:key: ", p), err)
                }
        }
        return err
}
{{noformat}}

Looking at the Java code this looks quite similar, except the Java compiler 
does not generate it for the internal Arg structs.

{{code}}
      public void write(org.apache.thrift.protocol.TProtocol oprot, 
createJob_args struct) throws org.apache.thrift.TException {
        struct.validate();

        oprot.writeStructBegin(STRUCT_DESC);
        if (struct.description != null) {
          oprot.writeFieldBegin(DESCRIPTION_FIELD_DESC);
          struct.description.write(oprot);
          oprot.writeFieldEnd();
        }
        if (struct.lock != null) {
          oprot.writeFieldBegin(LOCK_FIELD_DESC);
          struct.lock.write(oprot);
          oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
      }
{{code}}

> Can not send nil pointer as service method argument
> ---------------------------------------------------
>
>                 Key: THRIFT-3533
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3533
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.9.3
>            Reporter: Chris Bannister
>         Attachments: 0001-go-compiler-handle-nil-fields-correctly.patch
>
>
> If you try to send a nil struct as an argument to a service method a panic 
> occurs as it tries to write out all the fields in the struct, the python 
> generated code has guarding 'if self.x != None:' for every struct field, 
> whereas Go only outputs the 'if p.IsSet()' when the field is declared 
> optional, which is not possible for argument lists.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to