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 55611938b170e8b58d31212a888fbdd7c17b2e9f
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Jan 18 08:54:26 2026 -0500

    Better exception messages from FastDateParser.parse(String)
---
 src/changes/changes.xml                                      |  1 +
 .../java/org/apache/commons/lang3/time/FastDateParser.java   | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0d9a02b98..08224fe6f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -98,6 +98,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory, 
David Du">Simplify literal assignments in ArrayFillTest #1567.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory, 
David Du">Make ArrayUtils methods implementation consistent with other 
overloads #1568.</action>
     <action                   type="fix" dev="ggregory" due-to="ThrawnCA, Gary 
Gregory">Fix handling of null marker in StringUtils.abbreviate(String, String, 
int, int) #1571.</action>
+    <action                   type="fix" dev="ggregory" due-to="Gary 
Gregory">Better exception messages from FastDateParser.parse(String).</action>
     <!-- ADD -->
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add JavaVersion.JAVA_27.</action>
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add SystemUtils.IS_JAVA_27.</action>
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 a9e6344a3..b5f7afe21 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
@@ -47,6 +47,7 @@
 import org.apache.commons.lang3.ArraySorter;
 import org.apache.commons.lang3.CharUtils;
 import org.apache.commons.lang3.LocaleUtils;
+import org.apache.commons.lang3.StringUtils;
 
 /**
  * FastDateParser is a fast and thread-safe version of {@link 
java.text.SimpleDateFormat}.
@@ -323,7 +324,7 @@ boolean parse(final FastDateParser parser, final Calendar 
calendar, final String
          */
         @Override
         public String toString() {
-            return "NumberStrategy [field=" + field + "]";
+            return getClass().getSimpleName() + " [field=" + field + "]";
         }
     }
 
@@ -1027,11 +1028,12 @@ public Date parse(final String source) throws 
ParseException {
         final Date date = parse(source, pp);
         if (date == null) {
             // Add a note regarding supported date range
+            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("(The " + locale + " locale does not 
support dates before 1868 AD)\nUnparseable date: \"" + source,
-                        pp.getErrorIndex());
+                throw new ParseException(String.format("; the %s locale does 
not support dates before 1868-01-01.", locale, msg), errorIndex);
             }
-            throw new ParseException("Unparseable date: " + source, 
pp.getErrorIndex());
+            throw new ParseException(msg, errorIndex);
         }
         return date;
     }
@@ -1129,6 +1131,6 @@ public String toString() {
      */
     public String toStringAll() {
         return "FastDateParser [pattern=" + pattern + ", timeZone=" + timeZone 
+ ", locale=" + locale + ", century=" + century + ", startYear=" + startYear
-                + ", patterns=" + patterns + "]";
+                + ", patterns=" + StringUtils.join(patterns, ", " + 
System.lineSeparator() + "\t") + "]";
     }
 }

Reply via email to