commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rostislav Krasny (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LANG-1420) TypeUtils.isAssignable returns wrong result for GenericArrayType and ParameterizedType comparison
Date Sat, 08 Dec 2018 01:05:00 GMT

    [ https://issues.apache.org/jira/browse/LANG-1420?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16713451#comment-16713451
] 

Rostislav Krasny edited comment on LANG-1420 at 12/8/18 1:04 AM:
-----------------------------------------------------------------

Adding following check into the suspected method fixes it:

{code}        if (type instanceof GenericArrayType) {
            return false;
        }{code}

Is it the right fix and should this check also be added into other private {{isAssignable()}}
methods where the second parameter isn't {{GenericArrayType}} ?


was (Author: rosti-il):
Adding following check into the {{isAssignable()}} method with {{ParameterizedType toParameterizedType}}
in signature fixes it

{code}        if (type instanceof GenericArrayType) {
            return false;
        }{code}

Is it the right fix and should this check also be added into other {{isAssignable()}} methods
where the second parameter isn't {{GenericArrayType}} ?

> 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.7, 3.8
>            Reporter: Gordon Fraser
>            Priority: Major
>
> 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)

Mime
View raw message