[ https://issues.apache.org/jira/browse/LANG-342?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell updated LANG-342: ------------------------------- Fix Version/s: 2.3.1 Setting fix version to 2.3.1 so the javadoc can be added. Then it should be reversioned to 3.0 for consideration there. > HashCodeBuilder.append(long) is incorrect > ----------------------------------------- > > Key: LANG-342 > URL: https://issues.apache.org/jira/browse/LANG-342 > Project: Commons Lang > Issue Type: Bug > Reporter: Benjamin Manes > Priority: Minor > Fix For: 2.3.1 > > > I was looking at using HashCodeBuilder rather than always writing out the > strategy by hand, and I noticed one potential mistake: > /** > * Append a hashCode for a long. > * > * @param value the long to add to the hashCode > * @return this > */ > public HashCodeBuilder append(long value) > { > iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32))); > return this; > } > > whereas Effective Java and Long.hashCode() use: > /** > * Returns a hash code for this <code>Long</code>. The result is > * the exclusive OR of the two halves of the primitive > * <code>long</code> value held by this <code>Long</code> > * object. That is, the hashcode is the value of the expression: > * <blockquote><pre> > * (int)(this.longValue()^(this.longValue()>>>32)) > * </pre></blockquote> > * > * @return a hash code value for this object. > */ > public int hashCode() { > return (int)(value ^ (value >>> 32)); > } > So the author accidentally used a signed right-shift rather than an unsigned. > ---- > Stephen Colebourne noted that while this is a bug, it is minor and could have > backward compatability issues. I would simply recommend that a non-JavaDoc > comment be added noting this method doesn't follow "Effective Java" correctly. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]