DeepSource has joined Harness. Learn more
Java logoJava/
JAVA-E1092

`ZoneId.of()` should be passed a valid timezone identifierJAVA-E1092

Major severityMajor
Bug Risk categoryBug Risk

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.

Use a valid timezone string.

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

References