You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Piotr Karwasz (Jira)" <ji...@apache.org> on 2025/06/02 10:13:00 UTC
[jira] [Commented] (LANG-1769) FastDateFormat.parse can not handle invalid input data
[ https://issues.apache.org/jira/browse/LANG-1769?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17955639#comment-17955639 ]
Piotr Karwasz commented on LANG-1769:
-------------------------------------
Hi [~sustech-whl],
{{FastDateFormat}} is a thread-safe alternative to {{SimpleDateFormat}}, and its behavior is designed to closely mirror that of {{SimpleDateFormat}}. In particular, it should only throw an exception in cases where {{SimpleDateFormat}} would also do so.
By default, {{SimpleDateFormat}} operates in a *lenient* mode, which means it accepts out-of-range values for date fields and attempts to normalize them (e.g., treating _February 29, 2025_ as a valid input referring to _March 1, 2025_).
If you want extend {{FastDateFormat}} to support a *string* mode, you should follow the same pattern as {{SimpleDateFormat}}:
* Add two methods: {{isLenient}} and {{setLenient}}.
* Implement the throwing behavior only if {{isLenient}} returns {{false}}.
> FastDateFormat.parse can not handle invalid input data
> ------------------------------------------------------
>
> Key: LANG-1769
> URL: https://issues.apache.org/jira/browse/LANG-1769
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.17.0
> Reporter: Wang Hailong
> Priority: Major
>
> the input is an invalid data, it should throw an exception, but the FastDateFormat.parse just parse it. The output is "Sun Jan 02 00:00:00 CST 10000
> "
> {color:#bbb529}@Test
> {color}{color:#cc7832}public void {color}{color:#ffc66d}testFastDateFormatWithInvalidMonth{color}() {color:#cc7832}throws {color}ParseException {
> {color:#808080}// Create a FastDateParser instance with a valid pattern string
> {color}{color:#808080} {color}FastDateFormat dateParser = FastDateFormat.getInstance({color:#6a8759}"MM/dd/yyyy"{color}{color:#cc7832}, new {color}Locale({color:#6a8759}"en"{color}{color:#cc7832}, {color}{color:#6a8759}"US"{color})){color:#cc7832};
> {color}{color:#cc7832} {color}{color:#808080}// Attempt to parse an invalid month value and expect an exception
> {color}{color:#808080} {color}System.{color:#9876aa}out{color}.println(dateParser.parse({color:#6a8759}"13/02/9999"{color})){color:#cc7832};
> {color}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)