Skip to content

Addition of fallback patterns to temporal parser loses cause in Spring 5.3.5 #26777

@petergphillips

Description

@petergphillips

Affects: 5.3.5

We've just pulled in the latest spring framework as a result of a spring boot upgrade to 2.4.4 and noticed that some of our unit tests are now failing as the error messages have now changed.

When we detect a validation failure our code calls e.getMostSpecificCause().getMessage() to get the reason for the failure. So for input value of 2019-30-17 we expect to get the error message of

Invalid value for MonthOfYear (valid values 1 - 12): 30

as that is what the root DateTimeException message is set to.

However it appears that changes for #20292 create a brand new DateTimeParseException without passing in the cause into the constructor on creation. This can be seen at

and should be changed to pass through the existing DateTimeException cause.

This means that the error message we now get is

Unable to parse date time value "2019-30-17" using configuration from @org.springframework.format.annotation.DateTimeFormat(pattern="", style="SS", iso=DATE, fallbackPatterns={})

which isn't nearly as human readable as the original, divulges inner spring annotations, and isn't suitable for end users. I understand that there is a desire to output the fallbackPatterns in case there are multiple specified, but I would have expected the underlying cause to be preserved so that applications can choose which cause to present to the user. Furthermore I wouldn't expect patch versions of spring to change the validation error messages.

In our spring boot code the field is annotated with

@DateTimeFormat(iso = ISO.DATE) @RequestParam(value = "from_date", required = false) LocalDate fromDate

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions