You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Owen O'Malley (JIRA)" <ji...@apache.org> on 2009/12/02 17:56:20 UTC

[jira] Commented: (HADOOP-6298) BytesWritable#getBytes is a bad name that leads to programming mistakes

    [ https://issues.apache.org/jira/browse/HADOOP-6298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784894#action_12784894 ] 

Owen O'Malley commented on HADOOP-6298:
---------------------------------------

This *would be* an API change. Renaming methods means that all of the clients need to change their code. I agree the name is unfortunate, precisely because String.toBytes() has different semantics.

Also note that this is both in Text and BytesWritable, so you really would need to do the same change on both of them.

I still don't think the pain is worth the gain. I'd suggest adding a new method that does what you want. Maybe something like:

{code}
/**
 * Get a copy of the bytes that is exactly the length of the data.
 */
public byte[] getSlicedBytes() {
  byte[] result = new byte[length];
  System.arraycopy(bytes, 0, result, 0, length);
  return result;
}
{code}

Once you have the method, you can change your examples to use it and your co-workers will follow suit. Do note that it has a cost in terms of performance...

> BytesWritable#getBytes is a bad name that leads to programming mistakes
> -----------------------------------------------------------------------
>
>                 Key: HADOOP-6298
>                 URL: https://issues.apache.org/jira/browse/HADOOP-6298
>             Project: Hadoop Common
>          Issue Type: Improvement
>    Affects Versions: 0.20.1
>            Reporter: Nathan Marz
>
> Pretty much everyone at Rapleaf who has worked with Hadoop has misused BytesWritable#getBytes at some point, not expecting the byte array to be padded. I think we can completely alleviate these programming mistakes by deprecating and renaming this method (again) to be more descriptive. I propose "getPaddedBytes()" or "getPaddedValue()". It would also be helpful to have a helper method "getNonPaddedValue()" that makes a copy into a non-padded byte array. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.