Skip to content

Commit fe19cfd

Browse files
committed
Tightened StringValueResolver contract
Issue: SPR-14842 (cherry picked from commit 20419d7)
1 parent fbad637 commit fe19cfd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ public Object getObject() throws BeansException {
372372
}
373373
catch (TypeMismatchException ex) {
374374
if (logger.isDebugEnabled()) {
375-
logger.debug("Failed to convert bean '" + name + "' to required type [" +
376-
ClassUtils.getQualifiedName(requiredType) + "]", ex);
375+
logger.debug("Failed to convert bean '" + name + "' to required type '" +
376+
ClassUtils.getQualifiedName(requiredType) + "'", ex);
377377
}
378378
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
379379
}
@@ -805,12 +805,15 @@ public boolean hasEmbeddedValueResolver() {
805805

806806
@Override
807807
public String resolveEmbeddedValue(String value) {
808+
if (value == null) {
809+
return null;
810+
}
808811
String result = value;
809812
for (StringValueResolver resolver : this.embeddedValueResolvers) {
813+
result = resolver.resolveStringValue(result);
810814
if (result == null) {
811815
return null;
812816
}
813-
result = resolver.resolveStringValue(result);
814817
}
815818
return result;
816819
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,8 +30,11 @@ public interface StringValueResolver {
3030

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

0 commit comments

Comments
 (0)