Skip to content

Commit 93d2287

Browse files
committed
UnsatisfiedDependencyException avoids duplicate nested exception message
Issue: SPR-14607
1 parent c4fff6d commit 93d2287

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.beans.factory;
1818

1919
import org.springframework.beans.BeansException;
20-
import org.springframework.util.ClassUtils;
20+
import org.springframework.util.StringUtils;
2121

2222
/**
2323
* Exception thrown when a bean depends on other beans or simple properties
@@ -46,7 +46,7 @@ public UnsatisfiedDependencyException(
4646

4747
super(resourceDescription, beanName,
4848
"Unsatisfied dependency expressed through bean property '" + propertyName + "'" +
49-
(msg != null ? ": " + msg : ""));
49+
(StringUtils.hasLength(msg) ? ": " + msg : ""));
5050
}
5151

5252
/**
@@ -59,7 +59,7 @@ public UnsatisfiedDependencyException(
5959
public UnsatisfiedDependencyException(
6060
String resourceDescription, String beanName, String propertyName, BeansException ex) {
6161

62-
this(resourceDescription, beanName, propertyName, (ex != null ? ex.getMessage() : ""));
62+
this(resourceDescription, beanName, propertyName, "");
6363
initCause(ex);
6464
}
6565

@@ -74,7 +74,9 @@ public UnsatisfiedDependencyException(
7474
public UnsatisfiedDependencyException(
7575
String resourceDescription, String beanName, InjectionPoint injectionPoint, String msg) {
7676

77-
super(resourceDescription, beanName, "Unsatisfied dependency expressed through " + injectionPoint + ": " + msg);
77+
super(resourceDescription, beanName,
78+
"Unsatisfied dependency expressed through " + injectionPoint +
79+
(StringUtils.hasLength(msg) ? ": " + msg : ""));
7880
this.injectionPoint = injectionPoint;
7981
}
8082

@@ -89,7 +91,7 @@ public UnsatisfiedDependencyException(
8991
public UnsatisfiedDependencyException(
9092
String resourceDescription, String beanName, InjectionPoint injectionPoint, BeansException ex) {
9193

92-
this(resourceDescription, beanName, injectionPoint, (ex != null ? ex.getMessage() : ""));
94+
this(resourceDescription, beanName, injectionPoint, "");
9395
initCause(ex);
9496
}
9597

0 commit comments

Comments
 (0)