seokhyeon moon created LANG-1700:
------------------------------------

             Summary: TypeUtils.isAssignable returns wrong result for 
ParameterizedType 
                 Key: LANG-1700
                 URL: https://issues.apache.org/jira/browse/LANG-1700
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.reflect.*
    Affects Versions: 3.12.0
            Reporter: seokhyeon moon


TypeUtils.isAssignable returns a wrong result when checkng wheter a 
ParameterziedType is assignable to another ParamterizedType.

Given class definitions as following, for example, 
{code:java}
class MyNonTransientException extends MyException { ... }
class MyException extends Exception implements Iterable<Throwable> { ... }
class LexOrdering<T> extends MyOrdering<Iterable<T>> implements Serializable { 
... }
class MyOrdering<T> implements MyComparator<T> { ... }
interface MyComparator<T> { ... }{code}

In this case,
{code:java}
ParameterizedType from = TypeUtils.parameterize(LexOrdering.class, 
MyNonTransientException.class);
ParameterizedType to = TypeUtils.parameterize(MyComparator.class, new 
WildcardTypeImpl(new Type[]{Object.class}, new 
Type[]{MyNonTransientException.class}));
TypeUtils.isAssignable(from, to){code}
returns true, but this should be false. First line translates to 
"MyComparator<Iterable<MyNonTransientException>>" and second one is 
"MyComparator<? super MyNonTransientException>". First type cannot be assigned 
to second one (Javac complains it)

 

It seems that the problem is the method:
{code:java}
private static Map<TypeVariable<?>, Type> getTypeArguments(final Type type, 
final Class<?> toClass, final Map<TypeVariable<?>, Type> 
subtypeVarAssigns){code}
which is called in 
{code:java}
private static boolean isAssignable(final Type type, final ParameterizedType 
toParameterizedType, final Map<TypeVariable<?>, Type> typeVarAssigns){code}
getTypeArguments returns the map "T -> java.lang.iterable<T>, T -> 
MyNonTransientException, T -> java.lang.Iterable<T>".
I think this should be something like "T -> 
java.lang.iterable<MyNonTransientException>, T -> MyNonTransientException, T -> 
java.lang.Iterable<MyNonTransientException>".



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to