[ https://issues.apache.org/jira/browse/THRIFT-3486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15054776#comment-15054776 ]
Benjamin Gould commented on THRIFT-3486: ---------------------------------------- This seems like a reasonable request to me. The generated code in setFieldValue() looks like this ("bin" is the name of the binary field): {code} switch (field) { ... case BIN: if (value == null) { unsetBin(); } else { setBin((ByteBuffer)value); } break; .... } {code} For getFieldValue() we get this: {code} switch (field) { .... case BIN: return getBin(); {/code} There are setter methods generated that accept both a byte[] and a ByteBuffer; there are also getter methods for both, but the ByteBuffer version is named getBufferForBin() and the byte array version is getBin(). The proposed change to allow setFieldValue() to accept a byte[] value seems reasonable to me, and I can work on a fix for this if no one objects. > Java generated `getFieldValue` is incompatible with `setFieldValue` for > binary values. > -------------------------------------------------------------------------------------- > > Key: THRIFT-3486 > URL: https://issues.apache.org/jira/browse/THRIFT-3486 > Project: Thrift > Issue Type: Improvement > Components: Java - Compiler > Reporter: Gospo > Priority: Minor > > h4. Problem description > In case of a binary field, _getFieldValue_ returns a _byte[]_ while > _setFieldValue_ expects a _ByteBuffer_. > This design yields an unexpected requirement and is error prone. > This is a perfectly fine use-case that a client wants to write a field value > from one object to another object of the same thrift generated class: > {code} > obj1.setFieldValue(SOME_FIELD, obj2.getFieldValue(SOME_FIELD)) > {code} > It is a reasonable assumption that if I use a getter to obtain some property > value, the corresponding setter should accept a value of the same type. > Currently if _SOME_FIELD_ is a binary type field an exception is thrown: > _java.lang.ClassCastException: [B cannot be cast to java.nio.ByteBuffer_. > h4. Change proposal > Setter _setFieldValue_ should accept _byte[]_ value for a binary field. -- This message was sent by Atlassian JIRA (v6.3.4#6332)