Open nosan opened 3 weeks ago
https://github.com/spring-projects/spring-boot/compare/main...nosan:spring-boot:gh-42782 contains a potential fix.
The message lookup for EL expressions like
${validatedValue}
and for Bean Validation attributes such as{max}
could be skipped. For example:size.person.name=${validatedValue} must be between {min} and {max}
. Currently,MessageSourceMessageInterpolator
tries to resolve {validatedValue}, {min} and {max} viaMessageSource
. Clearly, the first one is an EL expression, while the latter two are Bean Validation attributes.
This could introduce a breaking change. For example, if someone has a property like key=100
and they are currently using @NotBlank(message=${key})
, they might expect the result to be $100. However, I don't think this being a significant issue, as such usage is quite uncommon in validation messages.
When I was doing research for #42773, I came across two potential improvements for
MessageSourceMessageInterpolator
:MessageSource.setUseCodeAsDefaultMessage(true)
#28930 could be improved a little bit:If
MessageSource
contains the searched parameter, it should be used, even if the value is identical to the parameter itself.The solution for this is quite straightforward
${validatedValue}
and for Bean Validation attributes such as{max}
could be skipped. For example:size.person.name=${validatedValue} must be between {min} and {max}
. Currently,MessageSourceMessageInterpolator
tries to resolve {validatedValue}, {min} and {max} viaMessageSource
. Clearly, the first one is an EL expression, while the latter two are Bean Validation attributes.EL expression can be handled by:
Bean validation attributes:
UPDATE: I changed the initial description to make it clearer.