Skip to content

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

Merged
mspruc merged 1 commit intoapache:mainfrom
mattpapp:fix/recordtype-hashcode-equals-contract
Feb 23, 2026
Merged

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

Conversation

@mattpapp
Copy link
Contributor

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
Contributor 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)

Copy link
Contributor

@mspruc mspruc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sounds reasonable @mattpapp

@mspruc mspruc merged commit 85f5361 into apache:main Feb 23, 2026
4 checks passed
@mattpapp mattpapp deleted the fix/recordtype-hashcode-equals-contract branch February 23, 2026 21:09
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