Skip to content

Fix equals() on token details #927

Merged
ikbalkaya merged 2 commits intomainfrom
fix_equals_for_token_details
Mar 17, 2023
Merged

Fix equals() on token details #927
ikbalkaya merged 2 commits intomainfrom
fix_equals_for_token_details

Conversation

@ikbalkaya
Copy link
Contributor

Fixes #926

@ikbalkaya ikbalkaya self-assigned this Mar 17, 2023
@ikbalkaya ikbalkaya requested a review from owenpearson March 17, 2023 10:24
@github-actions github-actions bot temporarily deployed to staging/pull/927/features March 17, 2023 10:24 Inactive
@ikbalkaya ikbalkaya requested a review from AndyTWF March 17, 2023 10:24
@github-actions github-actions bot temporarily deployed to staging/pull/927/javadoc March 17, 2023 10:25 Inactive
Copy link
Contributor

@AndyTWF AndyTWF left a comment

Choose a reason for hiding this comment

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

The cast on line 363 would throw a ClassCastException if you tried to compare anything other than a TokenDetails or subclass to a TokenDetails. Is it better to leave this behaviour in place, as it very quickly shows to anyone working on the library that they're trying to make an illogical comparison?

@ikbalkaya
Copy link
Contributor Author

ikbalkaya commented Mar 17, 2023

The cast on line 363 would throw a ClassCastException if you tried to compare anything other than a TokenDetails or subclass to a TokenDetails. Is it better to leave this behaviour in place, as it very quickly shows to anyone working on the library that they're trying to make an illogical comparison?

The conventional contract in for equals in Java is to check type and return false if type isn't what is expected by the object itself. I do not think raising an exception on equals would be appropriate. In the meantime, I realized that hashcode also wasn't implemented for this which I added here 565aed9

@AndyTWF
Copy link
Contributor

AndyTWF commented Mar 17, 2023

The cast on line 363 would throw a ClassCastException if you tried to compare anything other than a TokenDetails or subclass to a TokenDetails. Is it better to leave this behaviour in place, as it very quickly shows to anyone working on the library that they're trying to make an illogical comparison?

The conventional contract in for equals in Java is to check type and return false if type isn't what is expected by the object itself. I do not think raising an exception on equals would be appropriate. In the meantime, I realized that hashcode also wasn't implemented for this which I added here 565aed9

Fair play - I wasn't able to find anything too authoritative on conventions when I looked, but happy to go with convention :)

@ikbalkaya ikbalkaya merged commit ffb48cb into main Mar 17, 2023
@ikbalkaya ikbalkaya deleted the fix_equals_for_token_details branch March 17, 2023 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

equals() for TokenDetails is broken

2 participants