TypeUtils.isAssignable should return true for ParametrizedType assignable to Object [SPR-5390] #10063
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Vincent De Rijcke opened SPR-5390 and commented
isAssignable( Object.class, /* parametrizedtype or genericarraytype */ ) should be true
Test case:
public class SpringTypeUtilsTest {
private static final List<Long> LIST_LONG = null;
private static final List<Long>[] LIST_LONG_ARRAY = null;
}
Proposed fix of TypeUtils.java:
//UPDATE isAssignable(Type lhsType, Type rhsType)
public static boolean isAssignable(Type lhsType, Type rhsType) {
if (lhsType == null) {
throw new IllegalArgumentException("Left-hand side type must not be null");
}
if (rhsType == null) {
throw new IllegalArgumentException("Right-hand side type must not be null");
}
// ADDED
if (lhsType == Object.class && ( rhsType instanceof ParameterizedType || rhsType instanceof GenericArrayType)) {
return true;
}
// END ADDED
if (lhsType instanceof ParameterizedType && rhsType instanceof ParameterizedType) {
return isAssignable((ParameterizedType) lhsType, (ParameterizedType) rhsType);
}
if (lhsType instanceof WildcardType) {
return isAssignable((WildcardType) lhsType, rhsType);
}
return false;
}
Affects: 2.5.6, 3.0 M1
The text was updated successfully, but these errors were encountered: