[
https://issues.apache.org/jira/browse/THRIFT-2974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14998438#comment-14998438
]
ASF GitHub Bot commented on THRIFT-2974:
----------------------------------------
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.
----
> writeToParcel throws NPE for optional enum fields
> -------------------------------------------------
>
> Key: THRIFT-2974
> URL: https://issues.apache.org/jira/browse/THRIFT-2974
> Project: Thrift
> Issue Type: Bug
> Components: Java - Compiler
> Affects Versions: 0.9.2, 0.9.3
> Reporter: David Li
> Assignee: Marek Kedzierski
>
> The recent change to the Java compiler added generated Android compatible,
> parcelable Thrift objects.
> https://github.com/apache/thrift/commit/f9b8f5e64137248ea2a1b95312916491d23ab94a#diff-80220be8df49fb98fe5f899544d8368dR1569
> However, for optional enum fields that are null, getValue() will throw an NPE
> because no checks are made that the enum is set before being written.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)