-
Notifications
You must be signed in to change notification settings - Fork 6k
JDK-8274686 : java.util.UUID#hashCode() should use Long.hashCode() #5811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8274686 : java.util.UUID#hashCode() should use Long.hashCode() #5811
Conversation
👋 Welcome back JarvisCraft! A progress list of the required criteria for merging this PR into |
@JarvisCraft The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Good catch, this is what I've missed in #4309 |
|
@JarvisCraft This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 24 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@RogerRiggs) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@JarvisCraft |
You do know that this might break things? If there are multiple versions of JDK present in some distributed system where participants do not agree on the hash code of an UUID value, it can behave erratically. For example using UUID as a key in a distributed cache like Infinispan is known to be troublesome if the hashCode of some key is not the same across the cluster. Usually there will not be a problem since all nodes in a cluster would use the same JDK version, but what about a rolling upgrade then? It would not be possible. I think at least this change needs to be documented in release notes. |
@plevart may have a point and since this patch doesn't really have any benefits then maybe this PR/issue can be closed. |
Sorry, I was mislead by the comment above that because the original hashCode function is different, the hashCode will be different too. But I think this is not the case here. Original function is this:
new function (with inlined Long.hashCode(long)) looks like this:
The difference is two-fold:
But those two differences do not affect the lower 32 bits of any of the intermediate results and therefore the end result is the same (unless I missed something). So I think no release notes is needed for this change. I think that #4309 also dealt with similar change which was then reverted as a consequence (I'll have to check to be sure). |
Yes, the reverted change to BitSet.hashCode in #4309 has the same property. It could be applied without any visible effect. |
@plevart should I then file a follow-up ticket for |
@JarvisCraft This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Hi there, just a friendly reminder on this PR (as @Bridgekeeper has attempted to mark it as stale). Is there anything what should be done in order to have this PR integrated or is it just waiting for its time? |
/sponsor Thanks for the ping. |
Going to push as commit cc2cac1.
Your commit was automatically rebased without conflicts. |
@RogerRiggs @JarvisCraft Pushed as commit cc2cac1. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This is trivial fix of JDK-8274686 which replaces manually-computed
int
-basedlong
hash-code.Because
Long#hashCode(long)
uses other hashing function than the one currently used here:jdk/src/java.base/share/classes/java/lang/Long.java
Lines 1440 to 1442 in 75d6688
the value of
hashCode()
will produce different result, however this does not seem to be a breaking change asUUID#hashCode()
is not specified.Note: the comment to the bug states:
But as there seemed to be no corresponding discussion in core-libs-dev and the change looks trivial, I considered that it is appropriate to open a PR which (if needed) may be used for discussion (especially, considering the fact that its comments get mirrored to the ML).
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5811/head:pull/5811
$ git checkout pull/5811
Update a local copy of the PR:
$ git checkout pull/5811
$ git pull https://git.openjdk.java.net/jdk pull/5811/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5811
View PR using the GUI difftool:
$ git pr show -t 5811
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5811.diff