<i18n dev> RFR: 8369184: SimpleTimeZone equals() Returns True for Unequal Instances with Different hashCode Values [v2]
Justin Lu
jlu at openjdk.org
Tue Oct 7 19:00:47 UTC 2025
On Mon, 6 Oct 2025 21:49:31 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:
>
> fixed typo
LGTM
src/java.base/share/classes/java/util/SimpleTimeZone.java line 871:
> 869: public int hashCode()
> 870: {
> 871: int hash = 31 * getID().hashCode() + rawOffset;
int hash = Objects.hash(getID(), rawOffset, useDaylight);
return !useDaylight ? hash : 31 * hash + Objects.hash(
startMonth, startDay, startDayOfWeek, startTime, endMonth, endDay, endDayOfWeek, endTime);
Seems reasonable to use `Objects.hash` here. Could save some lines if wanted?
test/jdk/java/util/TimeZone/SimpleTimeZoneHashCodeTest.java line 1:
> 1: /*
Include _equals_ in the test name as well? Perhaps _HashCodeEqualsTest_ or something along those lines.
-------------
Marked as reviewed by jlu (Committer).
PR Review: https://git.openjdk.org/jdk/pull/27660#pullrequestreview-3311435895
PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2411594933
PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2411564566
More information about the i18n-dev
mailing list