4949import org .springframework .context .ApplicationContext ;
5050import org .springframework .context .ApplicationContextAware ;
5151import org .springframework .context .MessageSource ;
52- import org .springframework .core .DefaultParameterNameDiscoverer ;
52+ import org .springframework .core .KotlinDetector ;
53+ import org .springframework .core .KotlinReflectionParameterNameDiscoverer ;
5354import org .springframework .core .ParameterNameDiscoverer ;
5455import org .springframework .core .io .Resource ;
5556import org .springframework .lang .Nullable ;
@@ -100,7 +101,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
100101 private ConstraintValidatorFactory constraintValidatorFactory ;
101102
102103 @ Nullable
103- private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer () ;
104+ private ParameterNameDiscoverer parameterNameDiscoverer ;
104105
105106 @ Nullable
106107 private Resource [] mappingLocations ;
@@ -117,6 +118,13 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
117118 private ValidatorFactory validatorFactory ;
118119
119120
121+ public LocalValidatorFactoryBean () {
122+ if (KotlinDetector .isKotlinReflectPresent ()) {
123+ this .parameterNameDiscoverer = new KotlinReflectionParameterNameDiscoverer ();
124+ }
125+ }
126+
127+
120128 /**
121129 * Specify the desired provider class, if any.
122130 * <p>If not specified, JSR-303's default search mechanism will be used.
@@ -188,7 +196,10 @@ public void setConstraintValidatorFactory(ConstraintValidatorFactory constraintV
188196 /**
189197 * Set the ParameterNameDiscoverer to use for resolving method and constructor
190198 * parameter names if needed for message interpolation.
191- * <p>Default is a {@link org.springframework.core.DefaultParameterNameDiscoverer}.
199+ * <p>Default is Hibernate Validator's own internal use of standard Java reflection,
200+ * with an additional {@link KotlinReflectionParameterNameDiscoverer} if Kotlin
201+ * is present. This may be overridden with a custom subclass or a Spring-controlled
202+ * {@link org.springframework.core.DefaultParameterNameDiscoverer} if necessary,
192203 */
193204 public void setParameterNameDiscoverer (ParameterNameDiscoverer parameterNameDiscoverer ) {
194205 this .parameterNameDiscoverer = parameterNameDiscoverer ;
0 commit comments