By DeepSource

TimeZone.getTimeZone should be passed correct timezone IDs JAVA-E1093

Bug risk

java.util.TimeZone.getTimeZone() should not be passed invalid time zone identifier strings, as this will make it fail silently and return GMT instead.

Java cannot check for invalid timezones at compile time, so it is up to the developer to ensure that the string provided is actually valid. To avoid accidentally using an invalid time zone, it is recommended to select from a known list of timezone identifiers, such as those provided by the ZoneId.getAvailableZoneIds() method.

Bad Practice

TimeZone tz = TimeZone.getTimeZone("invalid/timezone"); // tz is assigned the GMT time zone.


Use a valid timezone string.

TimeZone tz = TimeZone.getTimeZone("America/New_York");