You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2017/05/31 21:00:08 UTC
[jira] [Resolved] (THRIFT-3703) Unions Field Count Does Not
Consider Map/Set/List Fields
[ https://issues.apache.org/jira/browse/THRIFT-3703?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jens Geyer resolved THRIFT-3703.
--------------------------------
Resolution: Fixed
Fix Version/s: 0.11.0
Committed.
> 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
> Fix For: 0.11.0
>
>
> 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)