Skip to content

Comments

fix: RecordType.hashCode() inconsistent with equals() (#694)#695

Open
mattpapp wants to merge 1 commit intoapache:mainfrom
mattpapp:fix/recordtype-hashcode-equals-contract
Open

fix: RecordType.hashCode() inconsistent with equals() (#694)#695
mattpapp wants to merge 1 commit intoapache:mainfrom
mattpapp:fix/recordtype-hashcode-equals-contract

Conversation

@mattpapp
Copy link

Fixes #694

hashCode() was using identity hash for the fieldNames array instead of content hash, while equals() correctly uses Arrays.equals(). Wrapped it with Arrays.hashCode() and added a test.

@mspruc
Copy link
Contributor

mspruc commented Feb 23, 2026

Hiya thanks for your contribution,

Do you know if BasicDataUnitType also needs to specify super.hashCode() in its implementation of hashCode()?

@mattpapp
Copy link
Author

@mspruc Hey! good question.

I don’t think BasicDataUnitType should include super.hashCode(). Its superclass (DataUnitType) doesn’t override hashCode/equals (adn has no state) so super.hashCode() would basically be Object.hashCode() and would make two equal BasicDataUnitType instances give different hashes.

RecordType including super.hashCode() is still correct since RecordType.equals() calls super.equals() (so the parent state/typeClass is part of equality)

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.

bug: RecordType.hashCode() violates equals/hashCode contract

2 participants