GitHub user ruijiang opened a pull request:

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

    Always use bit field or BitSet for isSetXXX

    This is to address the issue: 
https://issues.apache.org/jira/browse/THRIFT-1827
    Due to the the inconsistent behavior of isSet for primitive field and 
nullable field (e.g.., enum), enums with defaults will always have 
isSetAnyEnumField() as true when the class is initialized. Example:
    
    enum Gender {
        UNSPECIFIED = 0,
        FEMALE = 1,
        MALE = 2,
    }
    
    struct User {
        1: optional Gender gender = Gender.UNSPECIFIED,
        2: optional i32 age = 0;
    }
    
    With this change, the generated code will look like this:
    
      public User setGender(Gender gender) {
        if (gender == null) {
          setGenderIsSet(false);
          return this;
        }
        this.gender = gender;
        setGenderIsSet(true);
        return this;
      }
    
      public void unsetGender() {
        this.gender = null;
        __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, 
__GENDER_ISSET_ID);
      }
    
      /** Returns true if field gender is set (has been assigned a value) and 
false otherwise */
      public boolean isSetGender() {
        return EncodingUtils.testBit(__isset_bitfield, __GENDER_ISSET_ID);
      }
    
      public void setGenderIsSet(boolean value) {
        if (!value) {
          this.gender = null;
        }
        __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, 
__GENDER_ISSET_ID, value);
      }
    
    I haven't tested this but just want to see if this the desired direction. 
If so I will do more testing and make sure it works.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ruijiang/thrift THRIFT-1827

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/161.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #161
    
----
commit 1c4c3c0983c6f7e87973b3bef2e52838b26c7960
Author: Rui Jiang <[email protected]>
Date:   2014-07-21T15:59:44Z

    Always use bit field or BitSet for isSetXXX

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to