GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — Avoid calling `actual.hashCode()` and `expected.hashCode()` in `DualValue` by davidboden · Pull Request #3340 · assertj/assertj ConversationThe hashCode of The current implementation caches the hashCode of both objects at construction, but this doesn't really match the requirement exactly. The motivation for changing this is around avoiding calling hashCode unnecessarily on actual and expected objects, but I think it fixes potential bugs too. You could:
Both of the DualValues would be equal to each other according to equals() but would have different hashcodes. We can continue to cache the hashCode if you prefer, but better to generate it based on the object references using Check List:
Following the contributing guidelines will make it easier for us to review and accept your PR.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. The hashCode of `DualValue` needs to match the object references of actual and expected, because that's what `equals` uses. The current implementation caches the hashCode of both objects at construction, but this doesn't really match the requirement exactly. The motivation for changing this is around avoiding calling hashCode unnecessarily on actual and expected objects, but I think it fixes potential bugs too. You could: * Create a DualValue. * Mutate a value in actual or expected that's present in the object's hashCode method. * Create another DualValue. Both of the DualValues would be equal to each other according to equals() but would have different hashcodes. We can continue to cache the hashCode if you prefer, but better to generate it based on the object references using `System.identityHashCode`.
|
There was an error while loading. Please reload this page.
|
I took a deeper look at the code and if we compute the hash code at construction time, I don't see a way that it could inconsistent with
If we compute the hash code every time Having said that, I think this PR is still relevant because the hash code computed based on I'm happy to be proven wrong, so don't hesitate if you find a test case invalidating my reasoning. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm taking over the PR, but you will be the commit author so full credit to you @davidboden |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @davidboden for your work, this is integrated.. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
actual.hashCode() and expected.hashCode() in DualValue
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.