Skip to content

Commit f735d12

Browse files
committed
UnsatisfiedDependencyException avoids duplicate nested exception message
Issue: SPR-14607 (cherry picked from commit 93d2287)
1 parent 7135bc2 commit f735d12

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.beans.BeansException;
2020
import org.springframework.util.ClassUtils;
21+
import org.springframework.util.StringUtils;
2122

2223
/**
2324
* Exception thrown when a bean depends on other beans or simple properties
@@ -46,7 +47,7 @@ public UnsatisfiedDependencyException(
4647

4748
super(resourceDescription, beanName,
4849
"Unsatisfied dependency expressed through bean property '" + propertyName + "'" +
49-
(msg != null ? ": " + msg : ""));
50+
(StringUtils.hasLength(msg) ? ": " + msg : ""));
5051
}
5152

5253
/**
@@ -59,7 +60,7 @@ public UnsatisfiedDependencyException(
5960
public UnsatisfiedDependencyException(
6061
String resourceDescription, String beanName, String propertyName, BeansException ex) {
6162

62-
this(resourceDescription, beanName, propertyName, (ex != null ? ex.getMessage() : ""));
63+
this(resourceDescription, beanName, propertyName, "");
6364
initCause(ex);
6465
}
6566

@@ -74,7 +75,9 @@ public UnsatisfiedDependencyException(
7475
public UnsatisfiedDependencyException(
7576
String resourceDescription, String beanName, InjectionPoint injectionPoint, String msg) {
7677

77-
super(resourceDescription, beanName, "Unsatisfied dependency expressed through " + injectionPoint + ": " + msg);
78+
super(resourceDescription, beanName,
79+
"Unsatisfied dependency expressed through " + injectionPoint +
80+
(StringUtils.hasLength(msg) ? ": " + msg : ""));
7881
this.injectionPoint = injectionPoint;
7982
}
8083

@@ -89,7 +92,7 @@ public UnsatisfiedDependencyException(
8992
public UnsatisfiedDependencyException(
9093
String resourceDescription, String beanName, InjectionPoint injectionPoint, BeansException ex) {
9194

92-
this(resourceDescription, beanName, injectionPoint, (ex != null ? ex.getMessage() : ""));
95+
this(resourceDescription, beanName, injectionPoint, "");
9396
initCause(ex);
9497
}
9598

0 commit comments

Comments
 (0)