This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit ef5de64ed438be8074ccb017c74c122d47b7195a
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Jun 8 16:19:41 2025 -0400

    Clean caches between tests
---
 .../commons/lang3/time/AbstractFormatCache.java       | 11 +++++++++--
 .../org/apache/commons/lang3/time/FastDateParser.java | 19 +++++++++++++------
 .../apache/commons/lang3/time/FastDatePrinter.java    |  9 ++++++---
 .../apache/commons/lang3/time/FastDateParserTest.java | 12 +++++++++++-
 4 files changed, 39 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/lang3/time/AbstractFormatCache.java 
b/src/main/java/org/apache/commons/lang3/time/AbstractFormatCache.java
index e8b3aa4fb..684f48b28 100644
--- a/src/main/java/org/apache/commons/lang3/time/AbstractFormatCache.java
+++ b/src/main/java/org/apache/commons/lang3/time/AbstractFormatCache.java
@@ -89,7 +89,14 @@ public int hashCode() {
      */
     static final int NONE = -1;
 
-    private static final ConcurrentMap<ArrayKey, String> 
cDateTimeInstanceCache = new ConcurrentHashMap<>(7);
+    private static final ConcurrentMap<ArrayKey, String> dateTimeInstanceCache 
= new ConcurrentHashMap<>(7);
+
+    /**
+     * Clears the cache.
+     */
+    static void clear() {
+        dateTimeInstanceCache.clear();
+    }
 
     /**
      * Gets a date/time format for the specified styles and locale.
@@ -104,7 +111,7 @@ public int hashCode() {
     static String getPatternForStyle(final Integer dateStyle, final Integer 
timeStyle, final Locale locale) {
         final Locale safeLocale = LocaleUtils.toLocale(locale);
         final ArrayKey key = new ArrayKey(dateStyle, timeStyle, safeLocale);
-        return cDateTimeInstanceCache.computeIfAbsent(key, k -> {
+        return dateTimeInstanceCache.computeIfAbsent(key, k -> {
             try {
                 final DateFormat formatter;
                 if (dateStyle == null) {
diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java 
b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
index e0d607c2e..845168a2e 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
@@ -42,6 +42,7 @@
 import java.util.concurrent.ConcurrentMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 import org.apache.commons.lang3.ArraySorter;
 import org.apache.commons.lang3.LocaleUtils;
@@ -630,7 +631,7 @@ public String toString() {
     // helper classes to parse the format string
 
     @SuppressWarnings("unchecked") // OK because we are creating an array with 
no entries
-    private static final ConcurrentMap<Locale, Strategy>[] caches = new 
ConcurrentMap[Calendar.FIELD_COUNT];
+    private static final ConcurrentMap<Locale, Strategy>[] CACHES = new 
ConcurrentMap[Calendar.FIELD_COUNT];
 
     private static final Strategy ABBREVIATED_YEAR_STRATEGY = new 
NumberStrategy(Calendar.YEAR) {
         /**
@@ -717,6 +718,13 @@ private static Map<String, Integer> 
appendDisplayNames(final Calendar calendar,
         return values;
     }
 
+    /**
+     * Clears the cache.
+     */
+    static void clear() {
+        
Stream.of(CACHES).filter(Objects::nonNull).forEach(ConcurrentMap::clear);
+    }
+
     /**
      * Gets a cache of Strategies for a particular field
      *
@@ -724,11 +732,11 @@ private static Map<String, Integer> 
appendDisplayNames(final Calendar calendar,
      * @return a cache of Locale to Strategy
      */
     private static ConcurrentMap<Locale, Strategy> getCache(final int field) {
-        synchronized (caches) {
-            if (caches[field] == null) {
-                caches[field] = new ConcurrentHashMap<>(3);
+        synchronized (CACHES) {
+            if (CACHES[field] == null) {
+                CACHES[field] = new ConcurrentHashMap<>(3);
             }
-            return caches[field];
+            return CACHES[field];
         }
     }
 
@@ -786,7 +794,6 @@ private static StringBuilder simpleQuote(final 
StringBuilder sb, final String va
 
     /** Initialized from Calendar. */
     private transient List<StrategyAndWidth> patterns;
-
     /**
      * Constructs a new FastDateParser.
      *
diff --git a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java 
b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
index 19aee12d2..21bf770b1 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
@@ -899,8 +899,7 @@ public int estimateLength() {
 
     private static final int MAX_DIGITS = 10; // log10(Integer.MAX_VALUE) ~= 
9.3
 
-    private static final ConcurrentMap<TimeZoneDisplayKey, String> 
cTimeZoneDisplayCache =
-        new ConcurrentHashMap<>(7);
+    private static final ConcurrentMap<TimeZoneDisplayKey, String> 
timeZoneDisplayCache = new ConcurrentHashMap<>(7);
 
     /**
      * Appends two digits to the given buffer.
@@ -991,6 +990,10 @@ private static void appendFullDigits(final Appendable 
buffer, int value, int min
         }
     }
 
+    static void clear() {
+        timeZoneDisplayCache.clear();
+    }
+
     /**
      * Gets the time zone display name, using a cache for performance.
      *
@@ -1003,7 +1006,7 @@ private static void appendFullDigits(final Appendable 
buffer, int value, int min
     static String getTimeZoneDisplay(final TimeZone tz, final boolean 
daylight, final int style, final Locale locale) {
         final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, 
style, locale);
         // This is a very slow call, so cache the results.
-        return cTimeZoneDisplayCache.computeIfAbsent(key, k -> 
tz.getDisplayName(daylight, style, locale));
+        return timeZoneDisplayCache.computeIfAbsent(key, k -> 
tz.getDisplayName(daylight, style, locale));
     }
 
     /**
diff --git 
a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java 
b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
index afc3fa38f..c260e60ca 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -42,6 +42,8 @@
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.commons.lang3.SystemUtils;
 import org.apache.commons.lang3.function.TriFunction;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
@@ -50,7 +52,7 @@
 /**
  * Tests {@link org.apache.commons.lang3.time.FastDateParser}.
  */
-public class FastDateParserTest extends AbstractLangTest {
+class FastDateParserTest extends AbstractLangTest {
 
     private enum Expected1806 {
         India(INDIA, "+05", "+0530", "+05:30", true), Greenwich(TimeZones.GMT, 
"Z", "Z", "Z", false),
@@ -93,6 +95,14 @@ private enum Expected1806 {
 
     private static final Locale SWEDEN = new Locale("sv", "SE");
 
+    @BeforeEach
+    @AfterEach
+    void clear() {
+        AbstractFormatCache.clear();
+        FastDateParser.clear();
+        FastDatePrinter.clear();
+    }
+
     static void checkParse(final Locale locale, final Calendar cal, final 
SimpleDateFormat simpleDateFormat,
             final DateParser dateParser) {
         final String formattedDate = simpleDateFormat.format(cal.getTime());

Reply via email to