Skip to content

Fix inconsistent equals and hashcode when annotations are cleared#573

Merged
popematt merged 1 commit intoamazon-ion:masterfrom
popematt:master
Sep 18, 2023
Merged

Fix inconsistent equals and hashcode when annotations are cleared#573
popematt merged 1 commit intoamazon-ion:masterfrom
popematt:master

Conversation

@popematt
Copy link
Copy Markdown
Contributor

Issue #, if available:

None

Description of changes:

The hashing of annotations was inconsistent with equals. When the _annotations array was null or an empty array, then hashTypeAnnotations would return the original hash of the value. If _annotations was a non-empty array, but all of it's elements were null (i.e. no annotations), hashTypeAnnotations() would return valueHashSalt * original.

This change moves the "return if no annotations" check until after we've counted the annotations in the array to make sure that a null or 0-size array is hashed equivalently to a null-element array.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@popematt popematt requested a review from tgregg September 18, 2023 16:31
@popematt popematt merged commit 0a4b60e into amazon-ion:master Sep 18, 2023
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