wicket icon indicating copy to clipboard operation
wicket copied to clipboard

PageParameters.hashCode is inconsistent with equals for named parameters in a different order

Open dashorst opened this issue 3 weeks ago • 2 comments

PageParameters.equals and PageParameters.hashCode disagree about the named parameters, so two PageParameters that are equal can have different hash codes. That breaks the contract of Object.hashCode.

equals compares the named parameters regardless of their order: the lists must hold the same pairs, each the same number of times. hashCode uses namedParameters.hashCode(), the order-sensitive hash of the List<NamedPair>.

PageParameters a = new PageParameters().add("a", "1").add("b", "2");
PageParameters b = new PageParameters().add("b", "2").add("a", "1");

a.equals(b);                    // true
a.hashCode() == b.hashCode();   // false

Anything that puts PageParameters in a hash-based collection, or in a key that includes them, can treat these two as different. The fix is to make hashCode order-insensitive for the named parameters, for example by summing the hash codes of the pairs.

dashorst avatar Nov 08 '26 10:11 dashorst

I’ll implement the fix for PageParameters.hashCode() and add regression tests for reordered named parameters and duplicate pairs. I’ll submit a PR once the fix is tested.

Swarneil1905 avatar Nov 08 '26 17:11 Swarneil1905

Go ahead! I hadn't instructed my agent to tackle this, so it's yours. 👍

dashorst avatar Nov 08 '26 19:11 dashorst