Fix BaseGeometryFunction.hashCode to be consistent with equals - #1203
Merged
dr-jts merged 2 commits intoJun 17, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theObject.equals/hashCodecontract and causing them to misbehave as keys in hash-based collections.Changes Made:
parameterNamesfromBaseGeometryFunction.hashCode()so it uses exactly the fieldsequals()compares (name, parameter types, return type).equals/hashCodecontract.compareTo()remains ordered by name and return type only — coarser thanequals(), which theComparablecontract permits — so it is left unchanged.This was found by a conformance sweep of the
jts-ioandjts-appmodules forequals/hashCode/Comparableinconsistencies;jts-iowas clean.