Skip to content

Commit bac2371

Browse files
committed
2 parents e7d0cd0 + e25640f commit bac2371

File tree

232 files changed

+4459
-4405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+4459
-4405
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
5858
# Initializes the CodeQL tools for scanning.
5959
- name: Initialize CodeQL
60-
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18
60+
uses: github/codeql-action/init@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
6161
with:
6262
languages: ${{ matrix.language }}
6363
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -68,7 +68,7 @@ jobs:
6868
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
6969
# If this step fails, then you should remove it and run the build manually (see below)
7070
- name: Autobuild
71-
uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18
71+
uses: github/codeql-action/autobuild@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
7272

7373
# ℹ️ Command-line programs to run using the OS shell.
7474
# 📚 https://git.io/JvXDl
@@ -82,4 +82,4 @@ jobs:
8282
# make release
8383

8484
- name: Perform CodeQL Analysis
85-
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18
85+
uses: github/codeql-action/analyze@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19

.github/workflows/scorecards-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
persist-credentials: false
4646

4747
- name: "Run analysis"
48-
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # 2.4.1
48+
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # 2.4.2
4949
with:
5050
results_file: results.sarif
5151
results_format: sarif
@@ -64,6 +64,6 @@ jobs:
6464
retention-days: 5
6565

6666
- name: "Upload to code-scanning"
67-
uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18
67+
uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
6868
with:
6969
sarif_file: results.sarif

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ public int hashCode() {
8989
*/
9090
static final int NONE = -1;
9191

92-
private static final ConcurrentMap<ArrayKey, String> cDateTimeInstanceCache = new ConcurrentHashMap<>(7);
92+
private static final ConcurrentMap<ArrayKey, String> dateTimeInstanceCache = new ConcurrentHashMap<>(7);
93+
94+
/**
95+
* Clears the cache.
96+
*/
97+
static void clear() {
98+
dateTimeInstanceCache.clear();
99+
}
93100

94101
/**
95102
* Gets a date/time format for the specified styles and locale.
@@ -104,7 +111,7 @@ public int hashCode() {
104111
static String getPatternForStyle(final Integer dateStyle, final Integer timeStyle, final Locale locale) {
105112
final Locale safeLocale = LocaleUtils.toLocale(locale);
106113
final ArrayKey key = new ArrayKey(dateStyle, timeStyle, safeLocale);
107-
return cDateTimeInstanceCache.computeIfAbsent(key, k -> {
114+
return dateTimeInstanceCache.computeIfAbsent(key, k -> {
108115
try {
109116
final DateFormat formatter;
110117
if (dateStyle == null) {
@@ -121,7 +128,14 @@ static String getPatternForStyle(final Integer dateStyle, final Integer timeStyl
121128
});
122129
}
123130

124-
private final ConcurrentMap<ArrayKey, F> cInstanceCache = new ConcurrentHashMap<>(7);
131+
private final ConcurrentMap<ArrayKey, F> instanceCache = new ConcurrentHashMap<>(7);
132+
133+
/**
134+
* Clears the cache.
135+
*/
136+
void clearInstance() {
137+
instanceCache.clear();
138+
}
125139

126140
/**
127141
* Create a format instance using the specified pattern, time zone
@@ -218,7 +232,7 @@ public F getInstance(final String pattern, final TimeZone timeZone, final Locale
218232
final TimeZone actualTimeZone = TimeZones.toTimeZone(timeZone);
219233
final Locale actualLocale = LocaleUtils.toLocale(locale);
220234
final ArrayKey key = new ArrayKey(pattern, actualTimeZone, actualLocale);
221-
return cInstanceCache.computeIfAbsent(key, k -> createInstance(pattern, actualTimeZone, actualLocale));
235+
return instanceCache.computeIfAbsent(key, k -> createInstance(pattern, actualTimeZone, actualLocale));
222236
}
223237

224238
/**

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,21 @@ public class FastDateFormat extends Format implements DateParser, DatePrinter {
101101
*/
102102
public static final int SHORT = DateFormat.SHORT;
103103

104-
private static final AbstractFormatCache<FastDateFormat> cache = new AbstractFormatCache<FastDateFormat>() {
104+
private static final AbstractFormatCache<FastDateFormat> CACHE = new AbstractFormatCache<FastDateFormat>() {
105105
@Override
106106
protected FastDateFormat createInstance(final String pattern, final TimeZone timeZone, final Locale locale) {
107107
return new FastDateFormat(pattern, timeZone, locale);
108108
}
109109
};
110110

111+
/**
112+
* Clears the cache.
113+
*/
114+
static void clear() {
115+
AbstractFormatCache.clear();
116+
CACHE.clearInstance();
117+
}
118+
111119
/**
112120
* Gets a date formatter instance using the specified style in the
113121
* default time zone and locale.
@@ -119,7 +127,7 @@ protected FastDateFormat createInstance(final String pattern, final TimeZone tim
119127
* @since 2.1
120128
*/
121129
public static FastDateFormat getDateInstance(final int style) {
122-
return cache.getDateInstance(style, null, null);
130+
return CACHE.getDateInstance(style, null, null);
123131
}
124132

125133
/**
@@ -134,7 +142,7 @@ public static FastDateFormat getDateInstance(final int style) {
134142
* @since 2.1
135143
*/
136144
public static FastDateFormat getDateInstance(final int style, final Locale locale) {
137-
return cache.getDateInstance(style, null, locale);
145+
return CACHE.getDateInstance(style, null, locale);
138146
}
139147

140148
/**
@@ -150,7 +158,7 @@ public static FastDateFormat getDateInstance(final int style, final Locale local
150158
* @since 2.1
151159
*/
152160
public static FastDateFormat getDateInstance(final int style, final TimeZone timeZone) {
153-
return cache.getDateInstance(style, timeZone, null);
161+
return CACHE.getDateInstance(style, timeZone, null);
154162
}
155163

156164
/**
@@ -166,7 +174,7 @@ public static FastDateFormat getDateInstance(final int style, final TimeZone tim
166174
* pattern defined
167175
*/
168176
public static FastDateFormat getDateInstance(final int style, final TimeZone timeZone, final Locale locale) {
169-
return cache.getDateInstance(style, timeZone, locale);
177+
return CACHE.getDateInstance(style, timeZone, locale);
170178
}
171179

172180
/**
@@ -181,7 +189,7 @@ public static FastDateFormat getDateInstance(final int style, final TimeZone tim
181189
* @since 2.1
182190
*/
183191
public static FastDateFormat getDateTimeInstance(final int dateStyle, final int timeStyle) {
184-
return cache.getDateTimeInstance(dateStyle, timeStyle, null, null);
192+
return CACHE.getDateTimeInstance(dateStyle, timeStyle, null, null);
185193
}
186194

187195
/**
@@ -197,7 +205,7 @@ public static FastDateFormat getDateTimeInstance(final int dateStyle, final int
197205
* @since 2.1
198206
*/
199207
public static FastDateFormat getDateTimeInstance(final int dateStyle, final int timeStyle, final Locale locale) {
200-
return cache.getDateTimeInstance(dateStyle, timeStyle, null, locale);
208+
return CACHE.getDateTimeInstance(dateStyle, timeStyle, null, locale);
201209
}
202210

203211
/**
@@ -232,7 +240,7 @@ public static FastDateFormat getDateTimeInstance(final int dateStyle, final int
232240
*/
233241
public static FastDateFormat getDateTimeInstance(
234242
final int dateStyle, final int timeStyle, final TimeZone timeZone, final Locale locale) {
235-
return cache.getDateTimeInstance(dateStyle, timeStyle, timeZone, locale);
243+
return CACHE.getDateTimeInstance(dateStyle, timeStyle, timeZone, locale);
236244
}
237245

238246
/**
@@ -242,7 +250,7 @@ public static FastDateFormat getDateTimeInstance(
242250
* @return a date/time formatter
243251
*/
244252
public static FastDateFormat getInstance() {
245-
return cache.getInstance();
253+
return CACHE.getInstance();
246254
}
247255

248256
/**
@@ -255,7 +263,7 @@ public static FastDateFormat getInstance() {
255263
* @throws IllegalArgumentException if pattern is invalid
256264
*/
257265
public static FastDateFormat getInstance(final String pattern) {
258-
return cache.getInstance(pattern, null, null);
266+
return CACHE.getInstance(pattern, null, null);
259267
}
260268

261269
/**
@@ -269,7 +277,7 @@ public static FastDateFormat getInstance(final String pattern) {
269277
* @throws IllegalArgumentException if pattern is invalid
270278
*/
271279
public static FastDateFormat getInstance(final String pattern, final Locale locale) {
272-
return cache.getInstance(pattern, null, locale);
280+
return CACHE.getInstance(pattern, null, locale);
273281
}
274282

275283
/**
@@ -284,7 +292,7 @@ public static FastDateFormat getInstance(final String pattern, final Locale loca
284292
* @throws IllegalArgumentException if pattern is invalid
285293
*/
286294
public static FastDateFormat getInstance(final String pattern, final TimeZone timeZone) {
287-
return cache.getInstance(pattern, timeZone, null);
295+
return CACHE.getInstance(pattern, timeZone, null);
288296
}
289297

290298
/**
@@ -301,7 +309,7 @@ public static FastDateFormat getInstance(final String pattern, final TimeZone ti
301309
* or {@code null}
302310
*/
303311
public static FastDateFormat getInstance(final String pattern, final TimeZone timeZone, final Locale locale) {
304-
return cache.getInstance(pattern, timeZone, locale);
312+
return CACHE.getInstance(pattern, timeZone, locale);
305313
}
306314

307315
/**
@@ -315,7 +323,7 @@ public static FastDateFormat getInstance(final String pattern, final TimeZone ti
315323
* @since 2.1
316324
*/
317325
public static FastDateFormat getTimeInstance(final int style) {
318-
return cache.getTimeInstance(style, null, null);
326+
return CACHE.getTimeInstance(style, null, null);
319327
}
320328

321329
/**
@@ -330,7 +338,7 @@ public static FastDateFormat getTimeInstance(final int style) {
330338
* @since 2.1
331339
*/
332340
public static FastDateFormat getTimeInstance(final int style, final Locale locale) {
333-
return cache.getTimeInstance(style, null, locale);
341+
return CACHE.getTimeInstance(style, null, locale);
334342
}
335343

336344
/**
@@ -346,7 +354,7 @@ public static FastDateFormat getTimeInstance(final int style, final Locale local
346354
* @since 2.1
347355
*/
348356
public static FastDateFormat getTimeInstance(final int style, final TimeZone timeZone) {
349-
return cache.getTimeInstance(style, timeZone, null);
357+
return CACHE.getTimeInstance(style, timeZone, null);
350358
}
351359

352360
/**
@@ -362,7 +370,7 @@ public static FastDateFormat getTimeInstance(final int style, final TimeZone tim
362370
* pattern defined
363371
*/
364372
public static FastDateFormat getTimeInstance(final int style, final TimeZone timeZone, final Locale locale) {
365-
return cache.getTimeInstance(style, timeZone, locale);
373+
return CACHE.getTimeInstance(style, timeZone, locale);
366374
}
367375

368376
/** Our fast printer. */

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.concurrent.ConcurrentMap;
4343
import java.util.regex.Matcher;
4444
import java.util.regex.Pattern;
45+
import java.util.stream.Stream;
4546

4647
import org.apache.commons.lang3.ArraySorter;
4748
import org.apache.commons.lang3.LocaleUtils;
@@ -630,7 +631,7 @@ public String toString() {
630631
// helper classes to parse the format string
631632

632633
@SuppressWarnings("unchecked") // OK because we are creating an array with no entries
633-
private static final ConcurrentMap<Locale, Strategy>[] caches = new ConcurrentMap[Calendar.FIELD_COUNT];
634+
private static final ConcurrentMap<Locale, Strategy>[] CACHES = new ConcurrentMap[Calendar.FIELD_COUNT];
634635

635636
private static final Strategy ABBREVIATED_YEAR_STRATEGY = new NumberStrategy(Calendar.YEAR) {
636637
/**
@@ -717,18 +718,25 @@ private static Map<String, Integer> appendDisplayNames(final Calendar calendar,
717718
return values;
718719
}
719720

721+
/**
722+
* Clears the cache.
723+
*/
724+
static void clear() {
725+
Stream.of(CACHES).filter(Objects::nonNull).forEach(ConcurrentMap::clear);
726+
}
727+
720728
/**
721729
* Gets a cache of Strategies for a particular field
722730
*
723731
* @param field The Calendar field
724732
* @return a cache of Locale to Strategy
725733
*/
726734
private static ConcurrentMap<Locale, Strategy> getCache(final int field) {
727-
synchronized (caches) {
728-
if (caches[field] == null) {
729-
caches[field] = new ConcurrentHashMap<>(3);
735+
synchronized (CACHES) {
736+
if (CACHES[field] == null) {
737+
CACHES[field] = new ConcurrentHashMap<>(3);
730738
}
731-
return caches[field];
739+
return CACHES[field];
732740
}
733741
}
734742

@@ -786,7 +794,6 @@ private static StringBuilder simpleQuote(final StringBuilder sb, final String va
786794

787795
/** Initialized from Calendar. */
788796
private transient List<StrategyAndWidth> patterns;
789-
790797
/**
791798
* Constructs a new FastDateParser.
792799
*

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,7 @@ public int estimateLength() {
899899

900900
private static final int MAX_DIGITS = 10; // log10(Integer.MAX_VALUE) ~= 9.3
901901

902-
private static final ConcurrentMap<TimeZoneDisplayKey, String> cTimeZoneDisplayCache =
903-
new ConcurrentHashMap<>(7);
902+
private static final ConcurrentMap<TimeZoneDisplayKey, String> timeZoneDisplayCache = new ConcurrentHashMap<>(7);
904903

905904
/**
906905
* Appends two digits to the given buffer.
@@ -991,6 +990,10 @@ private static void appendFullDigits(final Appendable buffer, int value, int min
991990
}
992991
}
993992

993+
static void clear() {
994+
timeZoneDisplayCache.clear();
995+
}
996+
994997
/**
995998
* Gets the time zone display name, using a cache for performance.
996999
*
@@ -1003,7 +1006,7 @@ private static void appendFullDigits(final Appendable buffer, int value, int min
10031006
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) {
10041007
final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
10051008
// This is a very slow call, so cache the results.
1006-
return cTimeZoneDisplayCache.computeIfAbsent(key, k -> tz.getDisplayName(daylight, style, locale));
1009+
return timeZoneDisplayCache.computeIfAbsent(key, k -> tz.getDisplayName(daylight, style, locale));
10071010
}
10081011

10091012
/**

0 commit comments

Comments
 (0)