Skip to content

Commit 284cf3e

Browse files
committed
Rely on standard parameter name resolution in Bean Validation 3.0
Just configuring additional Kotlin reflection if Kotlin is present. Closes gh-29566
1 parent cbf25b7 commit 284cf3e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
import org.springframework.context.ApplicationContext;
5050
import org.springframework.context.ApplicationContextAware;
5151
import org.springframework.context.MessageSource;
52-
import org.springframework.core.DefaultParameterNameDiscoverer;
52+
import org.springframework.core.KotlinDetector;
53+
import org.springframework.core.KotlinReflectionParameterNameDiscoverer;
5354
import org.springframework.core.ParameterNameDiscoverer;
5455
import org.springframework.core.io.Resource;
5556
import 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

Comments
 (0)