Skip to content

Commit 64c9600

Browse files
committed
bugfix: Refactor timezone validation logic in FastDateParser to 3-digit timezone IDs, which have been deprecated in JDK 25
1 parent 9167659 commit 64c9600

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/org/apache/commons/lang3/time/FastDateParser.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.text.ParseException;
2424
import java.text.ParsePosition;
2525
import java.text.SimpleDateFormat;
26+
import java.time.ZoneId;
2627
import java.util.ArrayList;
2728
import java.util.Arrays;
2829
import java.util.Calendar;
@@ -46,7 +47,9 @@
4647

4748
import org.apache.commons.lang3.ArraySorter;
4849
import org.apache.commons.lang3.CharUtils;
50+
import org.apache.commons.lang3.JavaVersion;
4951
import org.apache.commons.lang3.LocaleUtils;
52+
import org.apache.commons.lang3.SystemUtils;
5053

5154
/**
5255
* FastDateParser is a fast and thread-safe version of {@link java.text.SimpleDateFormat}.
@@ -532,7 +535,7 @@ public String toString() {
532535
for (final String[] zoneNames : zones) {
533536
// offset 0 is the time zone ID and is not localized
534537
final String tzId = zoneNames[ID];
535-
if (tzId.equalsIgnoreCase(TimeZones.GMT_ID)) {
538+
if (isInvalidTimeZoneId(tzId)) {
536539
continue;
537540
}
538541
final TimeZone tz = TimeZone.getTimeZone(tzId);
@@ -561,7 +564,7 @@ public String toString() {
561564
}
562565
// Order is undefined.
563566
for (final String tzId : ArraySorter.sort(TimeZone.getAvailableIDs())) {
564-
if (tzId.equalsIgnoreCase(TimeZones.GMT_ID)) {
567+
if (isInvalidTimeZoneId(tzId)) {
565568
continue;
566569
}
567570
final TimeZone tz = TimeZone.getTimeZone(tzId);
@@ -612,6 +615,12 @@ public String toString() {
612615
return "TimeZoneStrategy [locale=" + locale + ", tzNames=" + tzNames + ", pattern=" + pattern + "]";
613616
}
614617

618+
private static boolean isInvalidTimeZoneId(String tzId) {
619+
return tzId.equalsIgnoreCase(TimeZones.GMT_ID)
620+
||
621+
(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_25)
622+
&& ZoneId.SHORT_IDS.containsKey(tzId));
623+
}
615624
}
616625

617626
/**

0 commit comments

Comments
 (0)