Changing the hashCode() method to return toHashCode() per the request in LANG-520
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@829285 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3d17fad6d6
commit
4f9c1c3777
|
@ -969,4 +969,16 @@ public class HashCodeBuilder {
|
|||
return iTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The computed <code>hashCode</code> from toHashCode() is returned due to the likelyhood
|
||||
* of bugs in mis-calling toHashCode() and the unlikelyness of it mattering what the hashCode for
|
||||
* HashCodeBuilder itself is.
|
||||
*
|
||||
* @return <code>hashCode</code> based on the fields appended
|
||||
*/
|
||||
public int hashCode() {
|
||||
return toHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -547,4 +547,13 @@ public class HashCodeBuilderTest extends TestCase {
|
|||
b.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures LANG-520 remains true
|
||||
*/
|
||||
public void testToHashCodeEqualsHashCode() {
|
||||
HashCodeBuilder hcb = new HashCodeBuilder(17, 37).append(new Object()).append('a');
|
||||
assertEquals("hashCode() is no longer returning the same value as toHashCode() - see LANG-520",
|
||||
hcb.toHashCode(), hcb.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue