Steven Walters (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiMGY4YzkyMWFlZ...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1772?atlOrigin=eyJpIjoiMGY4Yzky...
) HV-1772 (
https://hibernate.atlassian.net/browse/HV-1772?atlOrigin=eyJpIjoiMGY4Yzky...
) Building multiple ValidatorFactory instances from a single Configuration violates
specification for MessageInterpolator (
https://hibernate.atlassian.net/browse/HV-1772?atlOrigin=eyJpIjoiMGY4Yzky...
)
Issue Type: Bug Affects Versions: 5.4.3.Final, 6.0.19.Final, 7.0.0.Alpha1, 6.1.4.Final
Assignee: Unassigned Attachments: hibernate-validator-configuration-reuse-issue.zip
Components: engine Created: 28/Apr/2020 05:33 AM Priority: Major Reporter: Steven Walters
(
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
The bean validation specification mentions the following
Clients call Configuration.buildValidatorFactory() to retrieve the
initialized ValidatorFactory instance. It is legal to invoke
buildValidatorFactory() several times, e.g. in order to retrieve several
ValidatorFactory instances with a slightly different configuration (see
Using Configuration to create several validator factories).
to indicate that a Configuration can be used to create several ValidatorFactories, but
hibernate validation violates this aspect when it comes to MessageInterpolator.
I've attached a small maven project to implicate the issue. One can use
mvn clean verify -Phibernate5
mvn clean verify -Phibernate6
mvn clean verify -Phibernate61
mvn clean verify -Phibernate7
on the attached project to test the different versions (5.4.3.Final, 6.0.19.Final,
6.1.4.Final, and 7.0.0.Alpha1 respectively)
My investigation as to a possible RCA found that this is likely a regression from the
change introduced in HV-1131 (
https://hibernate.atlassian.net/browse/HV-1131 ) Closed ,
at HV-1131 code change (
https://github.com/hibernate/hibernate-validator/commit/c9948dabe5cb309d7...
) , which equates to once getMessageInterpolator() is invoked, the first return is
locked-in and all future invocations will always return the same value, even if
messageInterpolator() is utilized.
As a workaround to have hibernate respect the bean validation specification, one must
reflect on the Configuration and set the messageInterpolator field to null before doing
any operation that performs getMessageInterpolator(), such as buildValidatorFactory()
(which to honestly state is a rather dirty workaround)
I also cannot state that such a workaround will work long-term (such as with the module
system of Java 9+)
(
https://hibernate.atlassian.net/browse/HV-1772#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1772#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:29f7b81 )