This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new a2c873fb8 Correct null-locale Javadoc and add regression coverage
a2c873fb8 is described below
commit a2c873fb883dce1612f2ddb3078199c7bd8b9975
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Dec 3 14:11:54 2026 +0000
Correct null-locale Javadoc and add regression coverage
Document default-locale fallback in FastDateFormat, FastDateParser,
FastDatePrinter, ExtendedMessageFormat, and AbstractFormatCache.
Remove incorrect null-locale exception claims and correct four
default time zone descriptions.
Add Turkish case-conversion tests covering null locales, null and
empty strings, and explicit locale overrides. Add French locale
tests for date formatting, parsing, and date/time patterns.
---
.../commons/lang3/text/ExtendedMessageFormat.java | 4 ++--
.../commons/lang3/time/AbstractFormatCache.java | 10 ++++----
.../apache/commons/lang3/time/FastDateFormat.java | 8 +++----
.../apache/commons/lang3/time/FastDateParser.java | 4 ++--
.../apache/commons/lang3/time/FastDatePrinter.java | 4 ++--
.../org/apache/commons/lang3/StringUtilsTest.java | 18 +++++++++++++++
.../commons/lang3/time/FastDateFormatTest.java | 27 ++++++++++++++++++++++
.../commons/lang3/time/FastDateParserTest.java | 8 +++++++
8 files changed, 68 insertions(+), 15 deletions(-)
diff --git
a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
index c8db65cf4..9a3d126de 100644
--- a/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
+++ b/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
@@ -116,7 +116,7 @@ public ExtendedMessageFormat(final String pattern) {
* Create a new ExtendedMessageFormat.
*
* @param pattern The pattern to use, not null
- * @param locale The locale to use, not null
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
* @throws IllegalArgumentException Thrown in case of a bad pattern.
*/
public ExtendedMessageFormat(final String pattern, final Locale locale) {
@@ -127,7 +127,7 @@ public ExtendedMessageFormat(final String pattern, final
Locale locale) {
* Create a new ExtendedMessageFormat.
*
* @param pattern The pattern to use, not null.
- * @param locale The locale to use.
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
* @param registry The registry of format factories, may be null.
* @throws IllegalArgumentException Thrown in case of a bad pattern.
*/
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 fe9fc5767..5e564efc3 100644
--- a/src/main/java/org/apache/commons/lang3/time/AbstractFormatCache.java
+++ b/src/main/java/org/apache/commons/lang3/time/AbstractFormatCache.java
@@ -102,7 +102,7 @@ static void clear() {
*
* @param dateStyle date style: FULL, LONG, MEDIUM, or SHORT, null
indicates no date in format.
* @param timeStyle time style: FULL, LONG, MEDIUM, or SHORT, null
indicates no time in format.
- * @param locale The non-null locale of the desired format.
+ * @param locale The locale of the desired format, or {@code null} to use
{@link Locale#getDefault()}.
* @return A localized standard date/time format.
* @throws IllegalArgumentException Thrown if the Locale has no date/time
pattern defined.
*/
@@ -153,7 +153,7 @@ void clearInstance() {
* time zone and locale.
*
* @param dateStyle date style: FULL, LONG, MEDIUM, or SHORT.
- * @param timeZone optional time zone, overrides time zone of formatted
date, null means use default Locale.
+ * @param timeZone The time zone, or {@code null} to use {@link
TimeZone#getDefault()}.
* @param locale optional locale, overrides system locale.
* @return A localized standard date/time formatter.
* @throws IllegalArgumentException Thrown if the Locale has no date/time
pattern defined.
@@ -169,7 +169,7 @@ F getDateInstance(final int dateStyle, final TimeZone
timeZone, final Locale loc
*
* @param dateStyle date style: FULL, LONG, MEDIUM, or SHORT.
* @param timeStyle time style: FULL, LONG, MEDIUM, or SHORT.
- * @param timeZone optional time zone, overrides time zone of formatted
date, null means use default Locale.
+ * @param timeZone The time zone, or {@code null} to use {@link
TimeZone#getDefault()}.
* @param locale optional locale, overrides system locale.
* @return A localized standard date/time formatter.
* @throws IllegalArgumentException Thrown if the Locale has no date/time
pattern defined.
@@ -185,7 +185,7 @@ F getDateTimeInstance(final int dateStyle, final int
timeStyle, final TimeZone t
*
* @param dateStyle date style: FULL, LONG, MEDIUM, or SHORT, null
indicates no date in format.
* @param timeStyle time style: FULL, LONG, MEDIUM, or SHORT, null
indicates no time in format.
- * @param timeZone optional time zone, overrides time zone of formatted
date, null means use default Locale.
+ * @param timeZone The time zone, or {@code null} to use {@link
TimeZone#getDefault()}.
* @param locale optional locale, overrides system locale.
* @return A localized standard date/time formatter.
* @throws IllegalArgumentException Thrown if the Locale has no date/time
pattern defined.
@@ -236,7 +236,7 @@ public F getInstance(final String pattern, final TimeZone
timeZone, final Locale
* time zone and locale.
*
* @param timeStyle time style: FULL, LONG, MEDIUM, or SHORT.
- * @param timeZone optional time zone, overrides time zone of formatted
date, null means use default Locale.
+ * @param timeZone The time zone, or {@code null} to use {@link
TimeZone#getDefault()}.
* @param locale optional locale, overrides system locale.
* @return A localized standard date/time formatter.
* @throws IllegalArgumentException Thrown if the Locale has no date/time
pattern defined.
diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
b/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
index 2c3f7c8a8..9d10840f2 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java
@@ -376,8 +376,8 @@ public static FastDateFormat getTimeInstance(final int
style, final TimeZone tim
*
* @param pattern {@link java.text.SimpleDateFormat} compatible pattern.
* @param timeZone non-null time zone to use.
- * @param locale non-null locale to use.
- * @throws NullPointerException Thrown if pattern, timeZone, or locale is
null.
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
+ * @throws NullPointerException Thrown if pattern or timeZone is {@code
null}.
*/
protected FastDateFormat(final String pattern, final TimeZone timeZone,
final Locale locale) {
this(pattern, timeZone, locale, null);
@@ -388,10 +388,10 @@ protected FastDateFormat(final String pattern, final
TimeZone timeZone, final Lo
*
* @param pattern {@link java.text.SimpleDateFormat} compatible
pattern.
* @param timeZone non-null time zone to use.
- * @param locale non-null locale to use.
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
* @param centuryStart The start of the 100-year period to use as the
"default century" for 2 digit year parsing. If centuryStart is null, defaults
to now -
* 80 years.
- * @throws NullPointerException Thrown if pattern, timeZone, or locale is
null.
+ * @throws NullPointerException Thrown if pattern or timeZone is {@code
null}.
*/
protected FastDateFormat(final String pattern, final TimeZone timeZone,
final Locale locale, final Date centuryStart) {
printer = new FastDatePrinter(pattern, timeZone, locale);
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 beedde380..4064bb217 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
@@ -1011,7 +1011,7 @@ private static int toCalendarDayOfWeek(final int
isoDayOfWeek) {
*
* @param pattern non-null {@link java.text.SimpleDateFormat} compatible
pattern
* @param timeZone non-null time zone to use
- * @param locale non-null locale
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
*/
protected FastDateParser(final String pattern, final TimeZone timeZone,
final Locale locale) {
this(pattern, timeZone, locale, null);
@@ -1022,7 +1022,7 @@ protected FastDateParser(final String pattern, final
TimeZone timeZone, final Lo
*
* @param pattern non-null {@link java.text.SimpleDateFormat}
compatible pattern
* @param timeZone non-null time zone to use
- * @param locale locale, null maps to the default Locale.
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
* @param centuryStart The start of the century for 2 digit year parsing
* @since 3.5
*/
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 3592b0fb7..380af9e7a 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
@@ -1166,8 +1166,8 @@ static String getTimeZoneDisplay(final TimeZone tz, final
boolean daylight, fina
*
* @param pattern {@link java.text.SimpleDateFormat} compatible pattern.
* @param timeZone non-null time zone to use.
- * @param locale non-null locale to use.
- * @throws NullPointerException Thrown if pattern, timeZone, or locale is
null.
+ * @param locale The locale to use, or {@code null} to use {@link
Locale#getDefault()}.
+ * @throws NullPointerException Thrown if pattern or timeZone is {@code
null}.
*/
protected FastDatePrinter(final String pattern, final TimeZone timeZone,
final Locale locale) {
this.pattern = pattern;
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index 806899139..36d8bbfec 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -1485,6 +1485,15 @@ void testLowerCase() {
assertEquals("", StringUtils.lowerCase("", Locale.ENGLISH),
"lowerCase(empty-string, Locale) failed");
}
+ @Test
+ @DefaultLocale("tr")
+ void testLowerCaseNullLocale() {
+ assertNull(StringUtils.lowerCase(null, null));
+ assertEquals("", StringUtils.lowerCase("", null));
+ assertEquals("\u0131", StringUtils.lowerCase("I", null));
+ assertEquals("i", StringUtils.lowerCase("I", Locale.ENGLISH));
+ }
+
@Test
void testNormalizeSpace() {
// Character.isWhitespace excludes non-breaking space; normalizeSpace
converts it explicitly.
@@ -3441,6 +3450,15 @@ void testUpperCase() {
"upperCase(empty-string, Locale) failed");
}
+ @Test
+ @DefaultLocale("tr")
+ void testUpperCaseNullLocale() {
+ assertNull(StringUtils.upperCase(null, null));
+ assertEquals("", StringUtils.upperCase("", null));
+ assertEquals("\u0130", StringUtils.upperCase("i", null));
+ assertEquals("I", StringUtils.upperCase("i", Locale.ENGLISH));
+ }
+
@Test
void testWrap_StringChar() {
assertNull(StringUtils.wrap(null, CharUtils.NUL));
diff --git
a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
index 50f66b50d..4a2e080b4 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
@@ -23,6 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
+import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParseException;
@@ -278,6 +279,20 @@ void testCheckDifferingStyles() {
assertNotEquals(longShort, longLong);
}
+ @Test
+ @DefaultLocale(language = "fr", country = "FR")
+ void testConstructorNullLocale() throws ParseException {
+ final String pattern = "dd MMMM yyyy";
+ final Date date = new Date(0);
+ for (final FastDateFormat format : new FastDateFormat[] {
+ new FastDateFormat(pattern, TimeZones.GMT, null),
+ new FastDateFormat(pattern, TimeZones.GMT, null, date) }) {
+ assertEquals(Locale.FRANCE, format.getLocale());
+ assertEquals("01 janvier 1970", format.format(date));
+ assertEquals(date, format.parse("01 janvier 1970"));
+ }
+ }
+
@Test
@ReadsDefaultLocale
@ReadsDefaultTimeZone
@@ -439,6 +454,18 @@ public Object parseObject(final String source, final
ParsePosition pos) {
// System.out.println(">>FastDateFormatTest:
FastDateParser:"+fdfTime.get(1)+" SimpleDateFormat:"+sdfTime.get(1));
}
+ @Test
+ @DefaultLocale(language = "fr", country = "FR")
+ void testPatternForStyleNullLocale() {
+ final Integer style = Integer.valueOf(DateFormat.SHORT);
+ assertEquals(((SimpleDateFormat)
DateFormat.getDateInstance(DateFormat.SHORT, Locale.FRANCE)).toPattern(),
+ AbstractFormatCache.getPatternForStyle(style, null, null));
+ assertEquals(((SimpleDateFormat)
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.FRANCE)).toPattern(),
+ AbstractFormatCache.getPatternForStyle(null, style, null));
+ assertEquals(((SimpleDateFormat)
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
Locale.FRANCE)).toPattern(),
+ AbstractFormatCache.getPatternForStyle(style, style, null));
+ }
+
@Test
void testStandaloneLongMonthForm() {
final TimeZone utc = FastTimeZone.getGmtTimeZone();
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 7c46ac833..9f021f613 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -356,6 +356,14 @@ void testAmPm(final TriFunction<String, TimeZone, Locale,
DateParser> dpProvider
assertEquals(cal.getTime(), H.parse("2010-08-01 12:33:20"));
}
+ @Test
+ @DefaultLocale(language = "fr", country = "FR")
+ void testConstructorNullLocale() throws ParseException {
+ final FastDateParser parser = new FastDateParser("dd MMMM yyyy",
TimeZones.GMT, null);
+ assertEquals(Locale.FRANCE, parser.getLocale());
+ assertEquals(new Date(0), parser.parse("01 janvier 1970"));
+ }
+
@Test
void testDayNumberOfWeek() throws ParseException {
final DateParser parser = getInstance("u");