You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Frank Schroeder (JIRA)" <ji...@apache.org> on 2014/03/21 12:39:43 UTC

[jira] [Created] (THRIFT-2420) Go argument parser for methods without arguments does not skip fields

Frank Schroeder created THRIFT-2420:
---------------------------------------

             Summary: Go argument parser for methods without arguments does not skip fields
                 Key: THRIFT-2420
                 URL: https://issues.apache.org/jira/browse/THRIFT-2420
             Project: Thrift
          Issue Type: Bug
          Components: Go - Compiler
    Affects Versions: 0.9.2
         Environment: All
            Reporter: Frank Schroeder
             Fix For: 0.9.2


The Read() method of a struct of a thrift function which does not have arguments (e.g. foo()) calls iprot.ReadFieldBegin() to read the field type but does not consume/skip a field which it was not expecting. 

Read() methods for argument parsers for methods which have arguments have the correct code in the default section of the switch statement.

This is the current code (I've added where the iprot.Skip() call is missing):

{code}
func (p *GetVersionDataArgs) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return fmt.Errorf("%T read error: %s", p, err)
	}
	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return fmt.Errorf("%T field %d read error: %s", p, fieldId, err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		// should call iprot.Skip(fieldTypeId) if not STOP
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return fmt.Errorf("%T read struct end error: %s", p, err)
	}
	return nil
}
{code}

After the check for {{thrift.STOP}} there needs to be this code

{code}
		if err := iprot.Skip(fieldTypeId); err != nil {
			return err
		}
{code}

We've found this because on the Java side we dynamically inject fields into the struct on call which are ignored on the Go side as long as the function has arguments. When we make a call to the no-argument function some bytes are not consumed and make the thrift code go out of sync. 

I will attach a patch which fixes this. 



--
This message was sent by Atlassian JIRA
(v6.2#6252)