From 4371350b5d85f96243f2dd78b359036ea9074e85 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 10 Sep 2017 21:56:31 +0200 Subject: [PATCH] Polishing --- .../beans/factory/config/BeanDefinition.java | 3 ++- .../beans/factory/support/AbstractBeanFactory.java | 14 -------------- .../context/annotation/Profile.java | 2 +- .../springframework/web/bind/WebDataBinder.java | 4 +++- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java index 7663ea584f5..842c8e8c473 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java @@ -126,7 +126,8 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { void setScope(@Nullable String scope); /** - * Return the name of the current target scope for this bean. + * Return the name of the current target scope for this bean, + * or {@code null} if not known yet. */ @Nullable String getScope(); 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 7af742a9c03..a2c22d3ef12 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 @@ -368,18 +368,6 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } // Check if required type matches the type of the actual bean instance. - // Note that the following return declarations are technically violating the - // non-null policy for the getBean methods: However, these will only result - // in null under very specific circumstances: such as a user-declared factory - // method returning null or a user-provided FactoryBean.getObject() returning - // null, without any custom post-processing of such null values. We will pass - // them on as null to corresponding injection points in that exceptional case - // but do not expect user-level getBean callers to deal with such null values. - // In the end, regular getBean callers should be able to assign the outcome - // to non-null variables/arguments without being compromised by rather esoteric - // corner cases, in particular in functional configuration and Kotlin scenarios. - // A future Spring generation might eventually forbid null values completely - // and throw IllegalStateExceptions instead of leniently passing them through. if (requiredType != null && !requiredType.isInstance(bean)) { try { T convertedBean = getTypeConverter().convertIfNecessary(bean, requiredType); @@ -396,8 +384,6 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass()); } } - // For the nullability warning, see the elaboration in the comment above; - // in short: This is never going to be null unless user-declared code enforces null. return (T) bean; } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Profile.java b/spring-context/src/main/java/org/springframework/context/annotation/Profile.java index 0838238d4a5..35ab5d75818 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Profile.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Profile.java @@ -71,7 +71,7 @@ import org.springframework.core.env.ConfigurableEnvironment; * {@code @Profile} can therefore not be used to select an overloaded method with a * particular argument signature over another; resolution between all factory methods * for the same bean follows Spring's constructor resolution algorithm at creation time. - * Use distinct Java method names pointing to the same {@link @Bean#name bean name} + * Use distinct Java method names pointing to the same {@link Bean#name bean name} * if you'd like to define alternative beans with different profile conditions; * see {@code ProfileDatabaseConfig} in {@link Configuration @Configuration}'s javadoc. * diff --git a/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java index 7685be3fcb9..2a627dbd854 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java @@ -295,7 +295,9 @@ public class WebDataBinder extends DataBinder { } } catch (IllegalArgumentException ex) { - logger.debug("Failed to create default value - falling back to null: " + ex.getMessage()); + if (logger.isDebugEnabled()) { + logger.debug("Failed to create default value - falling back to null: " + ex.getMessage()); + } } // Default value: null. return null;