Gordon Fraser created LANG-1420:
-----------------------------------
Summary: TypeUtils.isAssignable returns wrong result for
GenericArrayType and ParameterizedType comparison
Key: LANG-1420
URL: https://issues.apache.org/jira/browse/LANG-1420
Project: Commons Lang
Issue Type: Bug
Components: lang.reflect.*
Affects Versions: 3.8, 3.7
Reporter: Gordon Fraser
TypeUtils.isAssignable returns a wrong result when checking whether a
ParameterizedType is assignable to a GenericArrayType that has the same
ParameterizedType as component type.
For example:
{code:java}
ParameterizedType componentType =
TypeUtils.parameterize(java.lang.reflect.Constructor.class,
java.awt.Insets.class);
GenericArrayType arrayType = TypeUtils.genericArrayType(componentType);{code}
In this case,
{code:java}
TypeUtils.isAssignable(arrayType, componentType) {code}
returns true, but this should be false (the component type should not be
assignable to the array type - the Java compiler complains about this).
It seem that the problem is that the method:
{code:java}
private static boolean isAssignable(final Type type, final ParameterizedType
toParameterizedType, final Map<TypeVariable<?>, Type> typeVarAssigns){code}
only compares the type parameters, since method getTypeArguments retrieves the
component type using getGenericComponentType. There seems to be no check
whether an array type is being assigned to a non-array in the first place.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)