From f735d12247e81bc36a36d5f5ca716a0d05e240f4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 23 Aug 2016 13:21:40 +0200 Subject: [PATCH] UnsatisfiedDependencyException avoids duplicate nested exception message Issue: SPR-14607 (cherry picked from commit 93d2287) --- .../beans/factory/UnsatisfiedDependencyException.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java index 0403abfc7a..666415dc64 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory; import org.springframework.beans.BeansException; import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; /** * Exception thrown when a bean depends on other beans or simple properties @@ -46,7 +47,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException { super(resourceDescription, beanName, "Unsatisfied dependency expressed through bean property '" + propertyName + "'" + - (msg != null ? ": " + msg : "")); + (StringUtils.hasLength(msg) ? ": " + msg : "")); } /** @@ -59,7 +60,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException { public UnsatisfiedDependencyException( String resourceDescription, String beanName, String propertyName, BeansException ex) { - this(resourceDescription, beanName, propertyName, (ex != null ? ex.getMessage() : "")); + this(resourceDescription, beanName, propertyName, ""); initCause(ex); } @@ -74,7 +75,9 @@ public class UnsatisfiedDependencyException extends BeanCreationException { public UnsatisfiedDependencyException( String resourceDescription, String beanName, InjectionPoint injectionPoint, String msg) { - super(resourceDescription, beanName, "Unsatisfied dependency expressed through " + injectionPoint + ": " + msg); + super(resourceDescription, beanName, + "Unsatisfied dependency expressed through " + injectionPoint + + (StringUtils.hasLength(msg) ? ": " + msg : "")); this.injectionPoint = injectionPoint; } @@ -89,7 +92,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException { public UnsatisfiedDependencyException( String resourceDescription, String beanName, InjectionPoint injectionPoint, BeansException ex) { - this(resourceDescription, beanName, injectionPoint, (ex != null ? ex.getMessage() : "")); + this(resourceDescription, beanName, injectionPoint, ""); initCause(ex); }