Java

Java

Made by DeepSource

ZoneId.of() should be passed a valid timezone identifier JAVA-E1092

Bug risk
Major

java.time.ZoneId.of() should not be passed invalid time zone identifier strings, as this will cause exceptions to be thrown at runtime.

ZoneId doesn't check the input string at compile-time, so it is up to the developer to ensure that the string provided is actually valid. To avoid errors, it is recommended to select from a known list of timezone identifiers, such as those provided by the ZoneId.getAvailableZoneIds() method.

Bad Practice

ZoneId zoneId = ZoneId.of("invalid/timezone");

Here, an invalid timezone string is passed to ZoneId.of(). This would cause a ZoneRulesException to be thrown.

Recommended

Use a valid timezone string.

ZoneId zoneId = ZoneId.of("America/New_York");

References