Skip to content

Commit 66d2c66

Browse files
committed
Improved fix for SPR-6850 by dealing with bounds separately from normal types
1 parent 7f90e3b commit 66d2c66

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

org.springframework.core/src/main/java/org/springframework/util/TypeUtils.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@ public abstract class TypeUtils {
4242
* @return true if rhs is assignable to lhs
4343
*/
4444
public static boolean isAssignable(Type lhsType, Type rhsType) {
45-
if (rhsType == null) {
46-
return true;
47-
}
48-
49-
if (lhsType == null) {
50-
return false;
51-
}
45+
Assert.notNull(lhsType, "Left-hand side type must not be null");
46+
Assert.notNull(rhsType, "Right-hand side type must not be null");
5247

5348
// all types are assignable to themselves and to class Object
5449
if (lhsType.equals(rhsType) || lhsType.equals(Object.class)) {
@@ -175,46 +170,58 @@ private static boolean isAssignable(WildcardType lhsType, Type rhsType) {
175170

176171
for (Type lBound : lUpperBounds) {
177172
for (Type rBound : rUpperBounds) {
178-
if (!isAssignable(lBound, rBound)) {
173+
if (!isAssignableBound(lBound, rBound)) {
179174
return false;
180175
}
181176
}
182177

183178
for (Type rBound : rLowerBounds) {
184-
if (!isAssignable(lBound, rBound)) {
179+
if (!isAssignableBound(lBound, rBound)) {
185180
return false;
186181
}
187182
}
188183
}
189184

190185
for (Type lBound : lLowerBounds) {
191186
for (Type rBound : rUpperBounds) {
192-
if (!isAssignable(rBound, lBound)) {
187+
if (!isAssignableBound(rBound, lBound)) {
193188
return false;
194189
}
195190
}
196191

197192
for (Type rBound : rLowerBounds) {
198-
if (!isAssignable(rBound, lBound)) {
193+
if (!isAssignableBound(rBound, lBound)) {
199194
return false;
200195
}
201196
}
202197
}
203198
}
204199
else {
205200
for (Type lBound : lUpperBounds) {
206-
if (!isAssignable(lBound, rhsType)) {
201+
if (!isAssignableBound(lBound, rhsType)) {
207202
return false;
208203
}
209204
}
210205

211206
for (Type lBound : lLowerBounds) {
212-
if (!isAssignable(rhsType, lBound)) {
207+
if (!isAssignableBound(rhsType, lBound)) {
213208
return false;
214209
}
215210
}
216211
}
217212

218213
return true;
219214
}
215+
216+
public static boolean isAssignableBound(Type lhsType, Type rhsType) {
217+
if (rhsType == null) {
218+
return true;
219+
}
220+
221+
if (lhsType == null) {
222+
return false;
223+
}
224+
return isAssignable(lhsType, rhsType);
225+
}
226+
220227
}

org.springframework.core/src/test/java/org/springframework/util/TypeUtilsTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public void withClasses() {
6666
assertTrue(TypeUtils.isAssignable(List.class, LinkedList.class));
6767
assertFalse(TypeUtils.isAssignable(List.class, Collection.class));
6868
assertFalse(TypeUtils.isAssignable(List.class, HashSet.class));
69-
assertFalse(TypeUtils.isAssignable(null, Object.class));
7069
}
7170

7271
@Test

0 commit comments

Comments
 (0)