RFR: 8285947: Avoid redundant HashMap.containsKey calls in ZoneName

Andrey Turbanov aturbanov at openjdk.java.net
Fri Apr 29 20:58:53 UTC 2022


On Fri, 29 Apr 2022 20:45:20 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

>> src/java.base/share/classes/java/time/format/ZoneName.java.template line 60:
>> 
>>> 58: 
>>> 59:     public static String toZid(String zid) {
>>> 60:         return aliases.getOrDefault(zid, zid);
>> 
>> Is the behavior if zid == null the same?  aliases.getOrDefault will throw NPE on null.
>> neither Hashmap.containsKey or .get throw on null.
>
>>aliases.getOrDefault will throw NPE on null
> 
> No, It will not. `aliases` is a HashMap. And HashMap supports null values and keys.

Anyway, this method is used only in `DateTimeFormatterBuilder` and it doesn't pass `null` value there.

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

PR: https://git.openjdk.java.net/jdk/pull/8463


More information about the core-libs-dev mailing list