RFR: 8275509: ModuleDescriptor.hashCode isn't reproducible across builds [v3]

Jaikiran Pai jpai at openjdk.java.net
Fri Oct 22 10:44:31 UTC 2021


> Can I please get a review for this change which fixes the issue reported in https://bugs.openjdk.java.net/browse/JDK-8275509?
> 
> The `ModuleDescriptor.hashCode()` method uses the hash code of its various components to compute the final hash code. While doing so it ends up calling hashCode() on (collection of) various `enum` types. Since the hashCode() of enum types is generated from a call to `java.lang.Object.hashCode()`, their value isn't guaranteed to stay the same across multiple JVM runs.
> 
> The commit here proposes to use the ordinal of the enum as the hash code. As Alan notes in the mailing list discussion, any changes to the ordinal of the enum (either due to addition of new value, removal of a value or just reordering existing values, all of which I think will be rare in these specific enum types) isn't expected to produce the same hash code across those changed runtimes and that should be okay. 
> 
> The rest of the ModuleDescriptor.hashCode() has been reviewed too and apart from calls to the enum types hashCode(), rest of the calls in that implementation, either directly or indirectly end up as calls on `java.lang.String.hashCode()` and as such aren't expected to cause non-deterministic values.
> 
> A new jtreg test has been added to reproduce this issue and verify the fix.

Jaikiran Pai has updated the pull request incrementally with one additional commit since the last revision:

  drop another final to make it consistent with rest of the code

-------------

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/6078/files
  - new: https://git.openjdk.java.net/jdk/pull/6078/files/c4ad8067..89669ea4

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=6078&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=6078&range=01-02

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/6078.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/6078/head:pull/6078

PR: https://git.openjdk.java.net/jdk/pull/6078


More information about the core-libs-dev mailing list