RFR: 8365077: java.awt.font.NumericShaper violates equals/hashCode contract
Phil Race
prr at openjdk.org
Mon Oct 13 18:01:17 UTC 2025
The problem here is that NumericShaper can be constructed either using Range enum members
or a bitmask.
And the bitmask can represent the same (equal) NumericShaper as one constructed using
the equivalent Range enum members and "boolean equals(Object)" handles this and there
is support in the Range enum for a Set<Range> for this which is used by equals.
However the hashCode() does not have similar support and is quite different.
The fix adds support for this.
If the instance has a Set<Range> then use this new support, which will return
the same hash as if it was constructed using a mask. In cases where this is not
possible because Range instances have no mask equivalent there is no issue
because these cannot be equal either.
EASTERN_ARABIC over-rides ARABIC and there was an inconsistency in that
when constructed with Ranges this ARABIC is removed but this isn't the case
for when constructed with masks.
I had to fix that so that the hashes would be the same.
I also made one variable final that should have been final all along.
A test is provided.
-------------
Commit messages:
- 8365077
Changes: https://git.openjdk.org/jdk/pull/27774/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27774&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8365077
Stats: 110 lines in 2 files changed: 100 ins; 8 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/27774.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/27774/head:pull/27774
PR: https://git.openjdk.org/jdk/pull/27774
More information about the client-libs-dev
mailing list