GitHub user bgould opened a pull request:

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

    Thrift 3486 - Java generated `getFieldValue` is incompatible with 
`setFieldValue` for binary values.

    For binary fields, the compiler generates Java getter/setter methods for 
primitive byte arrays (`byte[]`) as well as `java.nio.ByteBuffer` objects.  
However, `setFieldValue` only accepts a `ByteBuffer`, and throws a 
`ClassCastException` if a `byte[]` is passed as an argument. To further confuse 
things, `getFieldValue` returns a `byte[]`. By allowing either a `ByteBuffer` 
or a `byte[]` as input, `setFieldValue` could exhibit less confusing behavior 
for end users.
    
    These changes add an `instanceof` check for binary fields in the generated 
`setFieldValue()` method so that it accepts either a `byte[]` or a 
`ByteBuffer`.  There is also an update to the Java library's test suite to test 
for this functionality.

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

    $ git pull https://github.com/bgould/thrift THRIFT-3486

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

    https://github.com/apache/thrift/pull/743.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 #743
    
----
commit 9496213f8672fb3ea3c705d2c42bc10434b517a8
Author: BCG <bgo...@users.noreply.github.com>
Date:   2015-12-13T21:05:13Z

    Adding a test that fails without a fix for THRIFT-3468

commit 83cafef003b445d6ae3a98408c5b335b30256ada
Author: BCG <bgo...@users.noreply.github.com>
Date:   2015-12-13T21:20:32Z

    Added an 'instanceof' check for binary fields in the generated 
setFieldValue() method so that it accepts either a byte[] or a ByteBuffer.  The 
compiler generates getter/setter methods for both types, but previously 
setFieldValue only would accept a ByteBuffer.  To further confuse things, 
getFieldValue returns a byte[].  By allowing either a ByteBuffer or a byte[] as 
input, setFieldValue exhibits less confusing behavior for end users.

----


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to