Skip to content

Fix BaseGeometryFunction.hashCode to be consistent with equals - #1203

Merged
dr-jts merged 2 commits into
locationtech:masterfrom
grootstebozewolf:fix-app-basegeometryfunction-hashcode
Jun 17, 2026
Merged

Fix BaseGeometryFunction.hashCode to be consistent with equals#1203
dr-jts merged 2 commits into
locationtech:masterfrom
grootstebozewolf:fix-app-basegeometryfunction-hashcode

Conversation

@grootstebozewolf

Copy link
Copy Markdown
Contributor

BaseGeometryFunction.equals() defines two functions as equal when they have the same signature (name, parameter types and return type), and explicitly ignores parameter names. hashCode(), however, also mixed in the parameter names (Arrays.hashCode(parameterNames)), so two functions that are equal but differ only in their parameter names produced different hash codes — violating the Object.equals/hashCode contract and causing them to misbehave as keys in hash-based collections.

Changes Made:

  • Drop parameterNames from BaseGeometryFunction.hashCode() so it uses exactly the fields equals() compares (name, parameter types, return type).
  • Add a test for the equals/hashCode contract.
  • Update history (TestBuilder Bug Fixes).

compareTo() remains ordered by name and return type only — coarser than equals(), which the Comparable contract permits — so it is left unchanged.

This was found by a conformance sweep of the jts-io and jts-app modules for equals/hashCode/Comparable inconsistencies; jts-io was clean.

grootstebozewolf and others added 2 commits June 17, 2026 09:01
BaseGeometryFunction.equals() defines two functions as equal when they
have the same signature (name, parameter types and return type), and
explicitly ignores parameter names. hashCode(), however, also mixed in
the parameter names, so two functions that are equal but differ only in
their parameter names produced different hash codes -- violating the
Object.equals/hashCode contract and causing them to misbehave as keys in
hash-based collections.

Drop parameterNames from hashCode() so it uses exactly the fields equals()
compares. Adds a test for the equals/hashCode contract.

(compareTo() remains ordered by name and return type only -- coarser than
equals(), which the Comparable contract permits -- so it is left unchanged.)

Co-authored-by: Claude <noreply@anthropic.com>
@dr-jts
dr-jts merged commit 906b84d into locationtech:master Jun 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants