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

ASF GitHub Bot logged work on LANG-1420:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/Nov/20 16:49
            Start Date: 15/Nov/20 16:49
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on a change in pull request #643:
URL: https://github.com/apache/commons-lang/pull/643#discussion_r523783371



##########
File path: src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
##########
@@ -424,6 +424,11 @@ private static boolean isAssignable(final Type type, final 
ParameterizedType toP
             return true;
         }
 
+        //the component type should not be assignable to the array type

Review comment:
       This comment is backward.
   
   I've committed a variation of the PR to git master with more tests.
   
   I am wondering about other Type extensions. What do you think about 
`ypeUtilsTest.testIsAssignableGenericArrayTypeToWildercardType()`? See 
`isAssignable(Type, Type, Map<TypeVariable<?>, Type>)`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 511978)
    Time Spent: 0.5h  (was: 20m)

> TypeUtils.isAssignable returns wrong result for GenericArrayType and 
> ParameterizedType
> --------------------------------------------------------------------------------------
>
>                 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
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> 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
(v8.3.4#803005)

Reply via email to