Description
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:
- spr-14345.zip (71.26 kB)
Issue Links:
- TypeConverterSupport does not propagate custom exceptions anymore [SPR-14661] #19225 TypeConverterSupport does not propagate custom exceptions anymore
Referenced from: commits 367e663, f9e8924, c6f63bd, d51c22a
Backported to: 4.2.7