RFR: 8358624: ImmutableDescriptor violates equals/hashCode contract after deserialization [v3]
Serguei Spitsyn
sspitsyn at openjdk.org
Thu Jun 26 05:21:32 UTC 2025
On Wed, 25 Jun 2025 17:28:11 GMT, Kevin Walls <kevinw at openjdk.org> wrote:
>> 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.
>
> Kevin Walls has updated the pull request incrementally with one additional commit since the last revision:
>
> more comments!
Marked as reviewed by sspitsyn (Reviewer).
src/java.management/share/classes/javax/management/ImmutableDescriptor.java line 141:
> 139: bad = true;
> 140: if (!bad) {
> 141: hashCode = -1; // Force recalculation
Nit: Better to start the comment with low case. Same for other comments.
-------------
PR Review: https://git.openjdk.org/jdk/pull/25758#pullrequestreview-2960588030
PR Review Comment: https://git.openjdk.org/jdk/pull/25758#discussion_r2168131452
More information about the serviceability-dev
mailing list