From 66d2c6698b4642260cd3177407d036be4b0fc84a Mon Sep 17 00:00:00 2001 From: Ramnivas Laddad Date: Thu, 1 Apr 2010 23:37:08 +0000 Subject: [PATCH] Improved fix for SPR-6850 by dealing with bounds separately from normal types --- .../org/springframework/util/TypeUtils.java | 33 +++++++++++-------- .../springframework/util/TypeUtilsTests.java | 1 - 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/util/TypeUtils.java b/org.springframework.core/src/main/java/org/springframework/util/TypeUtils.java index 29c8ba849e2..6c98fb26f61 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/TypeUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/TypeUtils.java @@ -42,13 +42,8 @@ public abstract class TypeUtils { * @return true if rhs is assignable to lhs */ public static boolean isAssignable(Type lhsType, Type rhsType) { - if (rhsType == null) { - return true; - } - - if (lhsType == null) { - return false; - } + Assert.notNull(lhsType, "Left-hand side type must not be null"); + Assert.notNull(rhsType, "Right-hand side type must not be null"); // all types are assignable to themselves and to class Object if (lhsType.equals(rhsType) || lhsType.equals(Object.class)) { @@ -175,13 +170,13 @@ public abstract class TypeUtils { for (Type lBound : lUpperBounds) { for (Type rBound : rUpperBounds) { - if (!isAssignable(lBound, rBound)) { + if (!isAssignableBound(lBound, rBound)) { return false; } } for (Type rBound : rLowerBounds) { - if (!isAssignable(lBound, rBound)) { + if (!isAssignableBound(lBound, rBound)) { return false; } } @@ -189,13 +184,13 @@ public abstract class TypeUtils { for (Type lBound : lLowerBounds) { for (Type rBound : rUpperBounds) { - if (!isAssignable(rBound, lBound)) { + if (!isAssignableBound(rBound, lBound)) { return false; } } for (Type rBound : rLowerBounds) { - if (!isAssignable(rBound, lBound)) { + if (!isAssignableBound(rBound, lBound)) { return false; } } @@ -203,13 +198,13 @@ public abstract class TypeUtils { } else { for (Type lBound : lUpperBounds) { - if (!isAssignable(lBound, rhsType)) { + if (!isAssignableBound(lBound, rhsType)) { return false; } } for (Type lBound : lLowerBounds) { - if (!isAssignable(rhsType, lBound)) { + if (!isAssignableBound(rhsType, lBound)) { return false; } } @@ -217,4 +212,16 @@ public abstract class TypeUtils { return true; } + + public static boolean isAssignableBound(Type lhsType, Type rhsType) { + if (rhsType == null) { + return true; + } + + if (lhsType == null) { + return false; + } + return isAssignable(lhsType, rhsType); + } + } diff --git a/org.springframework.core/src/test/java/org/springframework/util/TypeUtilsTests.java b/org.springframework.core/src/test/java/org/springframework/util/TypeUtilsTests.java index 27a39da785b..b32dbbbb40e 100644 --- a/org.springframework.core/src/test/java/org/springframework/util/TypeUtilsTests.java +++ b/org.springframework.core/src/test/java/org/springframework/util/TypeUtilsTests.java @@ -66,7 +66,6 @@ public class TypeUtilsTests { assertTrue(TypeUtils.isAssignable(List.class, LinkedList.class)); assertFalse(TypeUtils.isAssignable(List.class, Collection.class)); assertFalse(TypeUtils.isAssignable(List.class, HashSet.class)); - assertFalse(TypeUtils.isAssignable(null, Object.class)); } @Test