From fe19cfde28a8c4803b96c08a49d63baf2969be78 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 28 Oct 2016 15:28:42 +0200 Subject: [PATCH] Tightened StringValueResolver contract Issue: SPR-14842 (cherry picked from commit 20419d7) --- .../beans/factory/support/AbstractBeanFactory.java | 9 ++++++--- .../org/springframework/util/StringValueResolver.java | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 62dfa38e42e..303484e6466 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -372,8 +372,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } catch (TypeMismatchException ex) { if (logger.isDebugEnabled()) { - logger.debug("Failed to convert bean '" + name + "' to required type [" + - ClassUtils.getQualifiedName(requiredType) + "]", ex); + logger.debug("Failed to convert bean '" + name + "' to required type '" + + ClassUtils.getQualifiedName(requiredType) + "'", ex); } throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass()); } @@ -805,12 +805,15 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @Override public String resolveEmbeddedValue(String value) { + if (value == null) { + return null; + } String result = value; for (StringValueResolver resolver : this.embeddedValueResolvers) { + result = resolver.resolveStringValue(result); if (result == null) { return null; } - result = resolver.resolveStringValue(result); } return result; } diff --git a/spring-core/src/main/java/org/springframework/util/StringValueResolver.java b/spring-core/src/main/java/org/springframework/util/StringValueResolver.java index acc77c1e645..f67de8f3645 100644 --- a/spring-core/src/main/java/org/springframework/util/StringValueResolver.java +++ b/spring-core/src/main/java/org/springframework/util/StringValueResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,11 @@ public interface StringValueResolver { /** * Resolve the given String value, for example parsing placeholders. - * @param strVal the original String value - * @return the resolved String value + * @param strVal the original String value (never {@code null}) + * @return the resolved String value (may be {@code null} when resolved to a null + * value), possibly the original String value itself (in case of no placeholders + * to resolve or when ignoring unresolvable placeholders) + * @throws IllegalArgumentException in case of an unresolvable String value */ String resolveStringValue(String strVal);