<i18n dev> RFR: 8369184: SimpleTimeZone equals() Returns True for Unequal Instances with Different hashCode Values [v2]

Naoto Sato naoto at openjdk.org
Tue Oct 7 20:43:23 UTC 2025


On Tue, 7 Oct 2025 18:54:34 GMT, Justin Lu <jlu at openjdk.org> wrote:

>> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   fixed typo
>
> 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?

Initially, I thought so, but decided to avoid extra array allocation/copy. But on second thought, the instances of this class would seldom be used as hash keys so not that performance critical. Either way is fine with me

> test/jdk/java/util/TimeZone/SimpleTimeZoneEqualsHashCodeTest.java line 1:
> 
>> (failed to retrieve contents of file, check the PR for context)
> Include _equals_ in the test name as well? Perhaps _HashCodeEqualsTest_ or something along those lines.

Renamed. I left `SimpleTimeZone` as the test is specific for this class.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2411787045
PR Review Comment: https://git.openjdk.org/jdk/pull/27660#discussion_r2411778576


More information about the i18n-dev mailing list