QueryBindingSet and MapBindingSet violate the contract of the hashCode() method

Description

QueryBindingSet and MapBindingSet implement BindingSet. An instance of either class can be compared to an instance of the other with equals(). When equals() returns true the hashCode() returns a different integer. This violates the contract of the hashCode() method (from the doc of Object.hashCode()):

  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

Note that hashCode() in Sesame 2.7.x and 2.8.6 is consistent with equals().

Sample code:
QueryBindingSet a = new QueryBindingSet();
a.addBinding("foo", new URIImpl("urn:bar"));

MapBindingSet b = new MapBindingSet();
b.addBinding("foo", new URIImpl("urn:bar"));

System.out.println(a.equals(b));
System.out.println(b.equals(a));
System.out.println(a.hashCode() == b.hashCode());

Environment

None

Assignee

Jeen Broekstra

Reporter

Pavel Mihaylov

Labels

None

Fix versions

Affects versions

Priority

Critical
Configure