Skip to content

Different error codes on same formatter registered in different ways [SPR-14345] #18917

Closed
@spring-projects-issues

Description

@spring-projects-issues

Ruslan Stelmachenko opened SPR-14345 and commented

Using Spring Web MVC.

When new org.springframework.format.Formatter registered using org.springframework.core.convert.ConversionService.addFormatter, then when conversion fails because of parse error (in Formatter.parse method), then catched exception in the end turns into org.springframework.beans.TypeMismatchException.

When the same formatter registered in controller's @InitBinder method using org.springframework.web.bind.WebDataBinder.addCustomFormatter, then when conversion fails because of parse error (in Formatter.parse method), then catched exception in the end turns into org.springframework.beans.MethodInvocationException.

This difference leads to new problem: when you use Spring's i18n feature (messages.properties) to localize error messages, then message code is different depending on how formatter was registered.

In first case it is: typeMismatch.*.
In second case it is: methodInvocation.*.

I'm not sure this is the intended behavior
It is very strange and inconvinient, that the same formatter throws different error message depending on the way in which it was registered.


Affects: 4.2.6

Attachments:

Issue Links:

Referenced from: commits 367e663, f9e8924, c6f63bd, d51c22a

Backported to: 4.2.7

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions