[hibernate-issues] [JIRA] (HV-1772) Building multiple ValidatorFactory instances from a single Configuration violates specification for MessageInterpolator

Steven Walters (JIRA) jira at hibernate.atlassian.net
Tue Apr 28 08:33:34 EDT 2020


Steven Walters ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A962aacfe-dd9c-432e-8471-9a7930e4c781 ) *created* an issue

Hibernate Validator ( https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiMGY4YzkyMWFlZmMyNGU4Y2FiMWViNzBjNjNhZGVkMWEiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HV-1772?atlOrigin=eyJpIjoiMGY4YzkyMWFlZmMyNGU4Y2FiMWViNzBjNjNhZGVkMWEiLCJwIjoiaiJ9 ) HV-1772 ( https://hibernate.atlassian.net/browse/HV-1772?atlOrigin=eyJpIjoiMGY4YzkyMWFlZmMyNGU4Y2FiMWViNzBjNjNhZGVkMWEiLCJwIjoiaiJ9 ) Building multiple ValidatorFactory instances from a single Configuration violates specification for MessageInterpolator ( https://hibernate.atlassian.net/browse/HV-1772?atlOrigin=eyJpIjoiMGY4YzkyMWFlZmMyNGU4Y2FiMWViNzBjNjNhZGVkMWEiLCJwIjoiaiJ9 )

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%3A962aacfe-dd9c-432e-8471-9a7930e4c781 )

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/c9948dabe5cb309d7f7d7f339b05906902d11ffd#diff-6a6fbbe9c367a3569c5155df33af912aR354 ) , 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=eyJpIjoiMGY4YzkyMWFlZmMyNGU4Y2FiMWViNzBjNjNhZGVkMWEiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1772#add-comment?atlOrigin=eyJpIjoiMGY4YzkyMWFlZmMyNGU4Y2FiMWViNzBjNjNhZGVkMWEiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:29f7b81 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200428/5664a0d9/attachment-0001.html 


More information about the hibernate-issues mailing list