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 dda928301 Keep FastDateParser.parse error message intact for imperial
locale (#1743)
dda928301 is described below
commit dda92830127b7486fb02932e87a05891feb9cef1
Author: alhuda <[email protected]>
AuthorDate: Mon Jul 6 17:38:55 2026 +0530
Keep FastDateParser.parse error message intact for imperial locale (#1743)
---
.../java/org/apache/commons/lang3/time/FastDateParser.java | 2 +-
.../org/apache/commons/lang3/time/FastDateParserTest.java | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
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 8966fc3f0..9ae90d61b 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
@@ -1028,7 +1028,7 @@ public Date parse(final String source) throws
ParseException {
final int errorIndex = pp.getErrorIndex();
final String msg = String.format("Unparseable date: '%s', parse
position = %s", source, pp);
if (locale.equals(JAPANESE_IMPERIAL)) {
- throw new ParseException(String.format("; the %s locale does
not support dates before 1868-01-01.", locale, msg), errorIndex);
+ throw new ParseException(String.format("%s; the %s locale does
not support dates before 1868-01-01.", msg, locale), errorIndex);
}
throw new ParseException(msg, errorIndex);
}
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 7847cf62b..ab3cf2b3c 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -426,6 +426,19 @@ void testLang1359(final TriFunction<String, TimeZone,
Locale, DateParser> dpProv
assertEquals(0, pos.getIndex());
}
+ @ParameterizedTest
+ @MethodSource(DATE_PARSER_PARAMETERS)
+ void testParseErrorMessageJapaneseImperial(final TriFunction<String,
TimeZone, Locale, DateParser> dpProvider) {
+ // The Japanese imperial branch of parse(String) must keep the
"Unparseable date" diagnostic
+ // (source text and parse position), not drop it and emit a message
starting with a stray ';'.
+ final DateParser fdp = getInstance(dpProvider, "yyyy", TimeZones.GMT,
FastDateParser.JAPANESE_IMPERIAL);
+ final String source = "not-a-date";
+ final ParseException e = assertThrows(ParseException.class, () ->
fdp.parse(source));
+ final String message = e.getMessage();
+ assertTrue(message.startsWith("Unparseable date: '" + source + "'"),
message);
+ assertTrue(message.contains("does not support dates before
1868-01-01."), message);
+ }
+
@ParameterizedTest
@MethodSource(DATE_PARSER_PARAMETERS)
void testLang1380(final TriFunction<String, TimeZone, Locale, DateParser>
dpProvider) throws ParseException {