TimeZone implementations questions

Andrey Turbanov turbanoff at gmail.com
Sat Jul 23 18:04:50 UTC 2022


Hello.
While I was browsing the source of java.util.TimeZone found a couple
of confusing things:

1. Static methods 'getAvailableIDs' and 'getAvailableIDs' are marked
as synchronized.
But all they do - just delegate call to sun.util.calendar.ZoneInfoFile methods:

public static synchronized String[] getAvailableIDs(int rawOffset) {
    return ZoneInfo.getAvailableIDs(rawOffset);
}

public static synchronized String[] getAvailableIDs() {
    return ZoneInfo.getAvailableIDs();
}
It seems 'synchronized's are unnecessary there. Am I right?

2. There is confusing NPE catch in a method 'java.util.TimeZone#setDefaultZone'

try {
    zoneID = getSystemTimeZoneID(javaHome);
    if (zoneID == null) {
        zoneID = GMT_ID;
    }
} catch (NullPointerException e) {
    zoneID = GMT_ID;
}

Only possible source of NPE here is the method 'getSystemTimeZoneID'.
I checked native sources and it seems there is no NPE thrown.
Can we remove the catch (NullPointerException)  then?



Andrey Turbanov


More information about the core-libs-dev mailing list