Skip to content

8358624: ImmutableDescriptor violates equals/hashCode contract after deserialization #25758

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kevinjwalls
Copy link
Contributor

@kevinjwalls kevinjwalls commented Jun 11, 2025

Hashcode needs to be reset to -1 to force its recalculation on next call, after deserialization.

The change in the readResolve() method is the fix for this problem. While here I added similar lines in other methods that may update fields (although these are noted as not supported, as they change a class supposedly "immutable").

Added a test. There is a test for serialization for this class, but I found it clearer to add the test for this specific recently discovered issue in its own test file.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8358624: ImmutableDescriptor violates equals/hashCode contract after deserialization (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25758/head:pull/25758
$ git checkout pull/25758

Update a local copy of the PR:
$ git checkout pull/25758
$ git pull https://git.openjdk.org/jdk.git pull/25758/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25758

View PR using the GUI difftool:
$ git pr show -t 25758

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25758.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 11, 2025

👋 Welcome back kevinw! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 11, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Jun 11, 2025

@kevinjwalls The following labels will be automatically applied to this pull request:

  • jmx
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@kevinjwalls kevinjwalls marked this pull request as ready for review June 11, 2025 15:17
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 11, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 11, 2025

Webrevs

@@ -138,6 +138,7 @@ private Object readResolve() throws InvalidObjectException {
if (names == null || values == null || names.length != values.length)
bad = true;
if (!bad) {
hashCode = -1; // Force recalculation
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Would it make sense to add same comment to the lines: 445, 452,473, 493?

@plummercj
Copy link
Contributor

I'm not much of a serialization expert, so just asking for some clarification here. I assume when de-serialized, the initial hashcode is always 0. Why it is 0 and not by default -1. Seems this would be an issue with any de-serialized type and all would need to explicitly set to -1 as you have done in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants