News from Jun 30, 2006

  2006/06/30
Error with Jakarta-commons HashCodeBuilder

I found interesting error in the code, which was very difficult to find out:

--------------------------------------------
return new HashCodeBuilder()
        .append(param1)
        .append(param2)
        .hashCode();
--------------------------------------------

This code is working incorrectly - it calculates different hash-code every time. This happening, because method ".hashCode()" is called on instance of class "HashCodeBuilder".

Instead of ".hashCode()" is needed to use ".toHashCode()".

Posted at 30 Jun @ 5:16 PM by sergei | 0 Comments