createZone() compares String values using == instead of .equals().
== compares object references rather than the actual String contents. This can work accidentally when callers pass string literals because of Java String interning, but it will fail when zoneId is created dynamically, such as from configuration, user input, string concatenation, or new String(...).
For example:
String zoneId = new String("US/Pacific");
In this case, zoneId == "US/Pacific" evaluates to false, causing createZone() to return null.
Please use .equals() for String comparison (or a String switch) so the comparison is based on the actual value.
createZone()compares String values using==instead of.equals().==compares object references rather than the actual String contents. This can work accidentally when callers pass string literals because of Java String interning, but it will fail whenzoneIdis created dynamically, such as from configuration, user input, string concatenation, ornew String(...).For example:
String zoneId = new String("US/Pacific");
In this case,
zoneId == "US/Pacific"evaluates tofalse, causingcreateZone()to returnnull.Please use
.equals()for String comparison (or a String switch) so the comparison is based on the actual value.