Disable lenient parsing in DateFormType#4175
Conversation
FastDateFormat.parseObject() silently accepted invalid dates by rolling over values (e.g. month 13 became month 1 of the next year). Use SimpleDateFormat with setLenient(false) to reject invalid dates.
|
Thanks @gilisd, Good catch. Looking at the existing code, there is now the dateFormat field which gets initialized in the constructor. However, it's now only used in the other method. Isn't there anything in the FastDateFormat class that can be used to reuse the field? |
FastDateFormat does not support lenient=false. Using local SimpleDateFormat instances in both methods avoids shared state and is thread-safe. The overhead of creating a new instance per call is acceptable as these methods are not expected to be called frequently on the same object.
Good point. FastDateFormat does not support setLenient(false) — it is explicitly lenient by default, so it cannot be used for strict parsing. We addressed your concern by removing the dateFormat field entirely. Both methods now use a local SimpleDateFormat instance, which keeps the code consistent and avoids shared state. Thread-safety is preserved since local variables are per-thread. The overhead of creating a new instance per call is acceptable as these methods are not expected to be called frequently on the same object. |
|
@gilisd in order to avoid the creation of the date pattern on every conversion, can't we create 2 fields? Thread safety is fine since we are not going to change those 2 fields at any time. |
|
@gilisd, thinking a bit more about this. This PR now fully disables lenient parsing and we switch the date format from Looking at the Javadoc of
Perhaps we need to keep the |
Date form properties now parse strictly by default, rejecting rolled-over dates (e.g. 15/13/2024) and trailing characters. The previous lenient behaviour can be restored per engine (ProcessEngineConfiguration) or per form property (lenientDateParsing attribute), with the property-level flag taking precedence. Formatting still uses FastDateFormat, so the output format is unchanged.
|
@jbarrez @filiphr Thanks for the review. I've reworked the PR based on your comments — a summary of what changed and why: FastDateFormat field restored — formatting unchanged. Why the strict parse path has no second field. Strict parsing now uses Backwards compatibility: Known limitations, intentionally left as-is: the property-level flag is only honoured when a |
filiphr
left a comment
There was a problem hiding this comment.
Thanks @DavidGilis. This looks OK to me. I'll let the CI run and then we can merge it
FastDateFormat.parseObject() silently accepted invalid dates by rolling over values (e.g. month 13 became month 1 of the next year). Use SimpleDateFormat with setLenient(false) to reject invalid dates.
Check List: