GitHub user maxspencer opened a pull request:

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

    THRIFT-2974 fix optional writeToParcel

    Fix for 
[THRIFT-2974](https://issues.apache.org/jira/browse/THRIFT-2974?jql=text%20~%20%22optional%20writeToParcel%22)
 which causes NPEs whenever struct with an unset optional enum is written to an 
Android 
[`Parcel`](http://developer.android.com/reference/android/os/Parcel.html#writeInt%28int%29).
    
    [Thrift IDL docs](https://thrift.apache.org/docs/idl#enum) specify that 
enum values must be greater than or equal to zero. We can write -1 to the 
parcel to represent an unset enum. The corresponding code for reconstructing 
the struct (see line 1728) uses the `TEnum.findByValue` method which will 
return `null` for any unused enum values, which will always include -1.

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

    $ git pull https://github.com/maxspencer/thrift patch-1

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

    https://github.com/apache/thrift/pull/687.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 #687
    
----
commit fb9aec028a47f14ad8377799425277f4c77a7cfe
Author: Max Spencer <[email protected]>
Date:   2015-11-10T11:34:19Z

    THRIFT-2974 fix optional writeToParcel
    
    Fix for 
[THRIFT-2974](https://issues.apache.org/jira/browse/THRIFT-2974?jql=text%20~%20%22optional%20writeToParcel%22)
 which causes NPEs whenever struct with an unset optional enum is written to an 
Android 
[`Parcel`](http://developer.android.com/reference/android/os/Parcel.html#writeInt%28int%29).
    
    [Thrift IDL docs](https://thrift.apache.org/docs/idl#enum) specify that 
enum values must be greater than or equal to zero so we can write -1 to the 
parcel to represent an unset enum. The corresponding code for reconstructing 
the struct (see line 1728) uses the `TEnum.findByValue` method which will 
return `null` for any unused enum values, which will always include -1.

----


---
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