Skip to content

Commit 20419d7

Browse files
committed
Tightened StringValueResolver contract
Issue: SPR-14842
1 parent 13001b9 commit 20419d7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ public Object getObject() throws BeansException {
370370
}
371371
catch (TypeMismatchException ex) {
372372
if (logger.isDebugEnabled()) {
373-
logger.debug("Failed to convert bean '" + name + "' to required type [" +
374-
ClassUtils.getQualifiedName(requiredType) + "]", ex);
373+
logger.debug("Failed to convert bean '" + name + "' to required type '" +
374+
ClassUtils.getQualifiedName(requiredType) + "'", ex);
375375
}
376376
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
377377
}
@@ -803,12 +803,15 @@ public boolean hasEmbeddedValueResolver() {
803803

804804
@Override
805805
public String resolveEmbeddedValue(String value) {
806+
if (value == null) {
807+
return null;
808+
}
806809
String result = value;
807810
for (StringValueResolver resolver : this.embeddedValueResolvers) {
811+
result = resolver.resolveStringValue(result);
808812
if (result == null) {
809813
return null;
810814
}
811-
result = resolver.resolveStringValue(result);
812815
}
813816
return result;
814817
}

spring-core/src/main/java/org/springframework/util/StringValueResolver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ public interface StringValueResolver {
3131

3232
/**
3333
* Resolve the given String value, for example parsing placeholders.
34-
* @param strVal the original String value
35-
* @return the resolved String value
34+
* @param strVal the original String value (never {@code null})
35+
* @return the resolved String value (may be {@code null} when resolved to a null
36+
* value), possibly the original String value itself (in case of no placeholders
37+
* to resolve or when ignoring unresolvable placeholders)
38+
* @throws IllegalArgumentException in case of an unresolvable String value
3639
*/
3740
String resolveStringValue(String strVal);
3841

0 commit comments

Comments
 (0)