[ 
https://issues.apache.org/jira/browse/WW-5812?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Lukasz Lenart resolved WW-5812.
-------------------------------
    Resolution: Fixed

> DateConverter rejects valid ISO yyyy-MM-dd dates when a lenient-only format 
> matches first
> -----------------------------------------------------------------------------------------
>
>                 Key: WW-5812
>                 URL: https://issues.apache.org/jira/browse/WW-5812
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core
>            Reporter: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.5.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> h2. Problem
> {{input type="date"}} always submits {{yyyy-MM-dd}}. When {{DateConverter}} 
> converts that value to {{java.util.Date}}, it rejects it under some locales 
> and global patterns with {{TypeConversionException: Could not parse date}}, 
> even though ISO {{yyyy-MM-dd}} is one of the formats it supports.
> ||Locale||{{"2026-10-24"}} → {{java.util.Date}}||
> |{{nl-NL}}|{{TypeConversionException: Could not parse date}}|
> |{{en-US}}, {{pl-PL}}|2026-10-24 (correct)|
> The format-selection loop picks the *first format that parses leniently*. It 
> then re-parses the input *strictly* with that one format and throws when the 
> strict parse fails. It never tries the remaining formats. Under {{nl-NL}} the 
> locale SHORT pattern {{dd-MM-y}} leniently accepts {{2026-10-24}} (as 18 Apr 
> 2030), so it is selected; the strict re-parse then fails, and the ISO format 
> later in the list is never tried. A global {{struts.date.format}} with {{-}} 
> separators, such as {{dd-MM-yyyy}}, fails the same way.
> The {{java.sql.Timestamp}} branch uses the same lenient-select / 
> strict-re-parse structure. The {{java.time}} branch is not affected: 
> {{DateTimeFormatter}} rejects the ISO string under these patterns, so ISO is 
> reached.
> An earlier version of this ticket said the value was silently misparsed. 
> Probing the real converter showed the result is a conversion error instead.
> This affects {{textfield type="date"}} bound to a {{java.util.Date}} 
> property, and {{datetextfield}} in the html5 theme (WW-5778).
> h2. Proposal
> Select the format *strictly* in the {{java.util.Date}} and 
> {{java.sql.Timestamp}} branches, so a format that only matches leniently is 
> skipped and the remaining formats are tried.
> * Format order is unchanged, so a configured global format still takes 
> precedence
> * Any input that converts today converts to the same value: a strict match is 
> always a lenient match, so the first strict match is the format selected today
> * Inputs that currently throw because a lenient-only format was selected will 
> now convert
> Tests: {{nl-NL}} locale and a {{dd-MM-yyyy}} global format for 
> {{java.util.Date}}, the {{Timestamp}} branch, and existing inputs unchanged.
> Related: WW-5778



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to