thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (THRIFT-3703) Unions Field Count Does Not Consider Map/Set/List Fields
Date Wed, 31 May 2017 20:58:04 GMT

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

ASF GitHub Bot commented on THRIFT-3703:
----------------------------------------

Github user asfgit closed the pull request at:

    https://github.com/apache/thrift/pull/1281


> Unions Field Count Does Not Consider Map/Set/List Fields
> --------------------------------------------------------
>
>                 Key: THRIFT-3703
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3703
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.9.3, 0.10.0
>         Environment: Ubuntu 15.10
>            Reporter: Tom Deering
>            Assignee: Can Celasun
>              Labels: golang, thrift, union
>
> Go code for unions generated by Thrift 0.9.3 fails to consider map/set/list fields of
a union when enforcing that the number of fields set is 1. For example:
> {code}
> union Foo{
>     1: map<bool,bool> u1
>     2: set<bool> u2,
>     3: list<bool> u3,
>     4: bool u4,
> }
> {code}
> Produces Go code:
> {code}
> type Foo struct {
> 	U1 map[bool]bool `thrift:"u1,1" json:"u1,omitempty"`
> 	U2 map[bool]bool `thrift:"u2,2" json:"u2,omitempty"`
> 	U3 []bool        `thrift:"u3,3" json:"u3,omitempty"`
> 	U4 *bool         `thrift:"u4,4" json:"u4,omitempty"`
> }
> ...
> func (p *Foo) CountSetFieldsFoo() int {
> 	count := 0
> 	if p.IsSetU4() {
> 		count++
> 	}
> 	return count
> }
> ...
> func (p *Foo) Write(oprot thrift.TProtocol) error {
> 	if c := p.CountSetFieldsFoo(); c != 1 {
> 		return fmt.Errorf("%T write union: exactly one field must be set (%d set).", p, c)
> 	}
> ...
> {code}
> Due to this bug, Thrift will complain that a union with only the fields u1, u2, or u3
set has no fields set. And it will allow all four fields to be set.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message