Skip to content

Commit f3f8610

Browse files
committed
Polish
1 parent c46bef1 commit f3f8610

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-instance.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-5.0.xsd">
5-
65
<instance-name>spring-boot</instance-name>
7-
86
<connection-strategy>
97
<connection-retry>
108
<cluster-connect-timeout-millis>60000</cluster-connect-timeout-millis>
119
</connection-retry>
1210
</connection-strategy>
13-
1411
<network>
1512
<cluster-members>
1613
<address>${address}</address>
1714
</cluster-members>
1815
</network>
19-
2016
</hazelcast-client>

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ private IgnoreTopLevelConverterNotFoundBindHandler getHandler() {
137137
: new IgnoreTopLevelConverterNotFoundBindHandler();
138138
}
139139

140-
@SuppressWarnings("unchecked")
141140
private List<Validator> getValidators(Bindable<?> target) {
142141
List<Validator> validators = new ArrayList<>(3);
143142
if (this.configurationPropertiesValidator != null) {
@@ -146,15 +145,23 @@ private List<Validator> getValidators(Bindable<?> target) {
146145
if (this.jsr303Present && target.getAnnotation(Validated.class) != null) {
147146
validators.add(getJsr303Validator());
148147
}
148+
Validator selfValidator = getSelfValidator(target);
149+
if (selfValidator != null) {
150+
validators.add(selfValidator);
151+
}
152+
return validators;
153+
}
154+
155+
private Validator getSelfValidator(Bindable<?> target) {
149156
if (target.getValue() != null) {
150-
if (target.getValue().get() instanceof Validator) {
151-
validators.add((Validator) target.getValue().get());
152-
}
157+
Object value = target.getValue().get();
158+
return (value instanceof Validator) ? (Validator) value : null;
153159
}
154-
else if (Validator.class.isAssignableFrom(target.getType().resolve())) {
155-
validators.add(new SelfValidatingConstructorBoundBindableValidator((Bindable<? extends Validator>) target));
160+
Class<?> type = target.getType().resolve();
161+
if (Validator.class.isAssignableFrom(type)) {
162+
return new SelfValidatingConstructorBoundBindableValidator(type);
156163
}
157-
return validators;
164+
return null;
158165
}
159166

160167
private Validator getJsr303Validator() {
@@ -271,15 +278,15 @@ private boolean isConfigurationProperties(Class<?> target) {
271278
*/
272279
static class SelfValidatingConstructorBoundBindableValidator implements Validator {
273280

274-
private final Bindable<? extends Validator> bindable;
281+
private final Class<?> type;
275282

276-
SelfValidatingConstructorBoundBindableValidator(Bindable<? extends Validator> bindable) {
277-
this.bindable = bindable;
283+
SelfValidatingConstructorBoundBindableValidator(Class<?> type) {
284+
this.type = type;
278285
}
279286

280287
@Override
281-
public boolean supports(Class<?> clazz) {
282-
return clazz.isAssignableFrom(this.bindable.getType().resolve());
288+
public boolean supports(Class<?> candidate) {
289+
return candidate.isAssignableFrom(this.type);
283290
}
284291

285292
@Override

0 commit comments

Comments
 (0)