<i18n dev> RFR: 8369184: SimpleTimeZone equals() Returns True for Unequal Instances with Different hashCode Values [v3]
Pavel Rappo
prappo at openjdk.org
Wed Oct 8 17:50:36 UTC 2025
On Tue, 7 Oct 2025 20:43:20 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> Fixing the equals/hashCode contract in the SimpleTimeZone class. The current implementation includes DST rule fields in hash code computation even for zones that do not observe DST, while equals() always considers them. Also correcting the example code in the class description, where it used 20-year-old obsolete "America/Los_Angeles" rule.
>
> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>
> Address review comments
test/jdk/java/util/TimeZone/SimpleTimeZoneEqualsHashCodeTest.java line 59:
> 57: assertNotEquals(STZ_WITH_DST, stz);
> 58: // from the contract point, hash codes may be the same
> 59: assertNotEquals(STZ_WITH_DST.hashCode(), stz.hashCode());
Like you said, from `!a.equals(b)` it does not follow that `a.hashCode() != b.hashCode()`. Unless you want hash code to specifically have this additional property, I'd remove this assertion.
test/jdk/java/util/TimeZone/SimpleTimeZoneEqualsHashCodeTest.java line 63:
> 61:
> 62: @Test
> 63: void withOutDSTTest() {
Nit, really:
Suggestion:
void withoutDSTTest() {
test/jdk/java/util/TimeZone/SimpleTimeZoneEqualsHashCodeTest.java line 76:
> 74: assertTrue(stz.useDaylightTime());
> 75: assertNotEquals(STZ_WITHOUT_DST, stz);
> 76: assertNotEquals(STZ_WITHOUT_DST.hashCode(), stz.hashCode());
Ditto on equals-hashCode contract.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2414592801
PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2414583906
PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2414599801
More information about the i18n-dev
mailing list