@@ -142,7 +142,6 @@ public ValidatorFactoryImpl(ConfigurationState configurationState) {
142142 ClassLoader externalClassLoader = getExternalClassLoader ( configurationState );
143143
144144 this .valueExtractorManager = new ValueExtractorManager ( configurationState .getValueExtractors () );
145- this .getterPropertyMatcher = new DefaultGetterPropertyMatcher ();
146145 this .beanMetaDataManagers = new ConcurrentHashMap <>();
147146 this .constraintHelper = new ConstraintHelper ();
148147 this .typeResolutionHelper = new TypeResolutionHelper ();
@@ -152,6 +151,9 @@ public ValidatorFactoryImpl(ConfigurationState configurationState) {
152151 if ( configurationState instanceof ConfigurationImpl ) {
153152 hibernateSpecificConfig = (ConfigurationImpl ) configurationState ;
154153 }
154+ Map <String , String > properties = configurationState .getProperties ();
155+
156+ this .getterPropertyMatcher = getGetterPropertyMatcher ( hibernateSpecificConfig , properties , externalClassLoader );
155157
156158 // HV-302; don't load XmlMappingParser if not necessary
157159 if ( configurationState .getMappingStreams ().isEmpty () ) {
@@ -167,14 +169,13 @@ public ValidatorFactoryImpl(ConfigurationState configurationState) {
167169 getConstraintMappings (
168170 typeResolutionHelper ,
169171 configurationState ,
172+ getterPropertyMatcher ,
170173 externalClassLoader
171174 )
172175 );
173176
174177 registerCustomConstraintValidators ( constraintMappings , constraintHelper );
175178
176- Map <String , String > properties = configurationState .getProperties ();
177-
178179 this .methodValidationConfiguration = new MethodValidationConfiguration .Builder ()
179180 .allowOverridingMethodAlterParameterConstraint (
180181 getAllowOverridingMethodAlterParameterConstraint ( hibernateSpecificConfig , properties )
@@ -213,7 +214,7 @@ private static ClassLoader getExternalClassLoader(ConfigurationState configurati
213214 }
214215
215216 private static Set <DefaultConstraintMapping > getConstraintMappings (TypeResolutionHelper typeResolutionHelper ,
216- ConfigurationState configurationState , ClassLoader externalClassLoader ) {
217+ ConfigurationState configurationState , GetterPropertyMatcher getterPropertyMatcher , ClassLoader externalClassLoader ) {
217218 Set <DefaultConstraintMapping > constraintMappings = newHashSet ();
218219
219220 if ( configurationState instanceof ConfigurationImpl ) {
@@ -229,7 +230,7 @@ private static Set<DefaultConstraintMapping> getConstraintMappings(TypeResolutio
229230 ConstraintMappingContributor serviceLoaderBasedContributor = new ServiceLoaderBasedConstraintMappingContributor (
230231 typeResolutionHelper ,
231232 externalClassLoader != null ? externalClassLoader : run ( GetClassLoader .fromContext () ) );
232- DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( constraintMappings );
233+ DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( getterPropertyMatcher , constraintMappings );
233234 serviceLoaderBasedContributor .createConstraintMappings ( builder );
234235 }
235236
@@ -238,7 +239,7 @@ private static Set<DefaultConstraintMapping> getConstraintMappings(TypeResolutio
238239 externalClassLoader );
239240
240241 for ( ConstraintMappingContributor contributor : contributors ) {
241- DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( constraintMappings );
242+ DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( getterPropertyMatcher , constraintMappings );
242243 contributor .createConstraintMappings ( builder );
243244 }
244245
@@ -294,6 +295,11 @@ public Duration getTemporalValidationTolerance() {
294295 return validatorFactoryScopedContext .getTemporalValidationTolerance ();
295296 }
296297
298+ @ Override
299+ public GetterPropertyMatcher getGetterPropertyMatcher () {
300+ return getterPropertyMatcher ;
301+ }
302+
297303 public boolean isFailFast () {
298304 return validatorFactoryScopedContext .isFailFast ();
299305 }
@@ -555,6 +561,32 @@ private Object getConstraintValidatorPayload(ConfigurationState configurationSta
555561 return null ;
556562 }
557563
564+ private static GetterPropertyMatcher getGetterPropertyMatcher (ConfigurationImpl hibernateSpecificConfig , Map <String , String > properties , ClassLoader externalClassLoader ) {
565+ if ( hibernateSpecificConfig .getGetterPropertyMatcher () != null ) {
566+ LOG .usingGetterPropertyMatcher ( hibernateSpecificConfig .getGetterPropertyMatcher ().getClass () );
567+ return hibernateSpecificConfig .getGetterPropertyMatcher ();
568+ }
569+
570+ String getterPropertyMatcherFqcn = properties .get ( HibernateValidatorConfiguration .GETTER_PROPERTY_MATCHER_CLASSNAME );
571+ if ( getterPropertyMatcherFqcn != null ) {
572+ try {
573+ @ SuppressWarnings ("unchecked" )
574+ Class <? extends GetterPropertyMatcher > clazz = (Class <? extends GetterPropertyMatcher >) run (
575+ LoadClass .action ( getterPropertyMatcherFqcn , externalClassLoader )
576+ );
577+ GetterPropertyMatcher getterPropertyMatcher = run ( NewInstance .action ( clazz , "getter property matcher class" ) );
578+ LOG .usingGetterPropertyMatcher ( clazz );
579+
580+ return getterPropertyMatcher ;
581+ }
582+ catch (Exception e ) {
583+ throw LOG .getUnableToInstantiateGetterPropertyMatcherClassException ( getterPropertyMatcherFqcn , e );
584+ }
585+ }
586+
587+ return new DefaultGetterPropertyMatcher ();
588+ }
589+
558590 private static void registerCustomConstraintValidators (Set <DefaultConstraintMapping > constraintMappings ,
559591 ConstraintHelper constraintHelper ) {
560592 Set <Class <?>> definedConstraints = newHashSet ();
@@ -603,16 +635,18 @@ private static <T> T run(PrivilegedAction<T> action) {
603635 */
604636 private static class DefaultConstraintMappingBuilder
605637 implements ConstraintMappingContributor .ConstraintMappingBuilder {
638+
639+ private final GetterPropertyMatcher getterPropertyMatcher ;
606640 private final Set <DefaultConstraintMapping > mappings ;
607641
608- public DefaultConstraintMappingBuilder (Set <DefaultConstraintMapping > mappings ) {
609- super () ;
642+ public DefaultConstraintMappingBuilder (GetterPropertyMatcher getterPropertyMatcher , Set <DefaultConstraintMapping > mappings ) {
643+ this . getterPropertyMatcher = getterPropertyMatcher ;
610644 this .mappings = mappings ;
611645 }
612646
613647 @ Override
614648 public ConstraintMapping addConstraintMapping () {
615- DefaultConstraintMapping mapping = new DefaultConstraintMapping ();
649+ DefaultConstraintMapping mapping = new DefaultConstraintMapping ( getterPropertyMatcher );
616650 mappings .add ( mapping );
617651 return mapping ;
618652 }
0 commit comments