Bug #298

ZToolAddress16 and ZToolAddress64 override equals() without overriding hashCode()

Added by Philipp Buluschek over 3 years ago.

Status:New Start date:02/06/2015
Priority:Normal Due date:
Assignee:- % Done:


Category:- Spent time: -
Target version:-
Has a patch:No Has license agreement signed:No


Both ZToolAddress16 and ZToolAddress64 redefine the equals() method but without redefining the hashCode() method.
If you override equals(), you must override hashCode()! hashCode() must generate equal values for equal objects.

This test currently fails:

public void testZToolAddressEquals() throws Exception {
  ZToolAddress16 a1 = new ZToolAddress16(0);
  ZToolAddress16 a2 = new ZToolAddress16(0);
  assertTrue(a1.equals(a2)); // ok passes

  Set<ZToolAddress16> s = new HashSet<ZToolAddress16>();
  assertTrue(s.contains(a2)); // fails here

Also available in: Atom PDF