Browse Source

Improved fix for SPR-6850 by dealing with bounds separately from normal types

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3220 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Ramnivas Laddad 16 years ago
parent
commit
c340cf02e0
  1. 33
      org.springframework.core/src/main/java/org/springframework/util/TypeUtils.java
  2. 1
      org.springframework.core/src/test/java/org/springframework/util/TypeUtilsTests.java

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

@ -42,13 +42,8 @@ public abstract class TypeUtils { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
}

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

@ -66,7 +66,6 @@ public class TypeUtilsTests { @@ -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

Loading…
Cancel
Save