-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Different error codes on same formatter registered in different ways [SPR-14345] #18917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Juergen Hoeller commented I can't reproduce this: With either variant, I consistently get a Could you please double-check your scenario there and provide a corresponding unit test? |
Ruslan Stelmachenko commented I've attached the mini-project to reproduce this. Run it with You will see Uncomment one of the lines in When formatter is registered using Also note, that if you enter just I thought |
Ruslan Stelmachenko commented I also found #12429 and see now that registering custom formatter using It's actualy not register formatter. It's register This is the reson why behaviour is different. For instanse, when
The But
Maybe this bridge ( |
Ruslan Stelmachenko commented So I think it should be something like this (simplified):
Or maybe using |
Juergen Hoeller commented Thanks for the analysis! It's indeed custom |
Juergen Hoeller commented Since Point taken about This will be available in the upcoming |
Ruslan Stelmachenko commented I'm tried And I agree with the arguments about the API contract. Thanks for the fixes! — But I should say, this will slightly change the behaviour of real property editors. For example:
After fix, it will cause I think this is "bad" property editor, because it violates
Maybe it is better if adapter will catch Of course it is only if the change of native ProperyEditors behavior is not intended. |
Juergen Hoeller commented From my perspective, that's ok: Exceptions coming out of |
Ruslan Stelmachenko opened SPR-14345 and commented
Using Spring Web MVC.
When new
org.springframework.format.Formatter
registered usingorg.springframework.core.convert.ConversionService.addFormatter
, then when conversion fails because of parse error (inFormatter.parse
method), then catched exception in the end turns intoorg.springframework.beans.TypeMismatchException
.When the same formatter registered in controller's
@InitBinder
method usingorg.springframework.web.bind.WebDataBinder.addCustomFormatter
, then when conversion fails because of parse error (inFormatter.parse method
), then catched exception in the end turns intoorg.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
The text was updated successfully, but these errors were encountered: