[ 
https://issues.apache.org/jira/browse/LANG-1749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory resolved LANG-1749.
-----------------------------------
    Fix Version/s: 3.21.0
       Resolution: Fixed

PR [https://github.com/apache/commons-lang/pull/1548] reviewed and merged; 
thank you. Please test your use case and/or a 3.21.0-SNAPSHOT build from 
[https://repository.apache.org/content/repositories/snapshots/] and close this 
ticket if appropriate.

> TypeUtils.isAssignable returns a wrong result for ParameterizedType when raw 
> class is "Class".
> ----------------------------------------------------------------------------------------------
>
>                 Key: LANG-1749
>                 URL: https://issues.apache.org/jira/browse/LANG-1749
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.reflect.*
>    Affects Versions: 3.14.0
>            Reporter: jinwoo choi
>            Priority: Major
>             Fix For: 3.21.0
>
>
> TypeUtils.isAssignable returns a wrong result for ParameterizedType when raw 
> class is "Class".
> Given class definitions as following, for example, 
> {code:java}
> class TestIF<T> {
> }
> class TestImpl<T> extends TestIF<T> {
> }
> class TestImpl2<R> extends TestIF<Number> {
> } {code}
>  
> Java compile error occurs as in the case below.
> {code:java}
> Class<? extends TestIF<?>> a1 = null;
> Class<TestIF> b1 = null;
> a1 = b1; //compile error
> Class<? extends TestIF<?>> a2 = null;
> Class<TestImpl> b2 = null;
> a2 = b2;  //compile error
> Class<? extends TestIF<Number>> a3 = null;
> Class<TestImpl2> b3 = null;
> a3 = b3;  //compile error {code}
>  
> but the isAssignable() returns true. it should be false. 
> {code:java}
> TypeVariable<?> typeVar1 = TestIF.class.getTypeParameters()[0];
> ParameterizedType topre1 = TypeUtils.parameterize(TestIF.class, 
> TypeUtils.wildcardType().build());
> Type to1 = TypeUtils.parameterize(Class.class, 
> TypeUtils.wildcardType().withUpperBounds(topre1).build());
> Type from1 = TypeUtils.parameterize(Class.class,  
> TypeUtils.parameterize(TestIF.class,typeVar1) );
> boolean result1 = TypeUtils.isAssignable(from1, to1);
> System.out.println("from : " + from1.toString() + " : to : " + to1.toString() 
> + " : " + result1);
> TypeVariable<?> typeVar2 = TestImpl.class.getTypeParameters()[0];
> ParameterizedType topre2 = TypeUtils.parameterize(TestIF.class, 
> TypeUtils.wildcardType().build());
> Type to2 = TypeUtils.parameterize(Class.class, 
> TypeUtils.wildcardType().withUpperBounds(topre2).build());
> Type from2 = TypeUtils.parameterize(Class.class,  
> TypeUtils.parameterize(TestImpl.class,typeVar2) );
> boolean result2 = TypeUtils.isAssignable(from2, to2);
> System.out.println("from : " + from2.toString() + " : to : " + to2.toString() 
> + " : " + result2);
> TypeVariable<?> typeVar3 = TestImpl2.class.getTypeParameters()[0];
> ParameterizedType topre3 = TypeUtils.parameterize(TestIF.class, 
> TypeUtils.wildcardType().build());
> Type to3 = TypeUtils.parameterize(Class.class, 
> TypeUtils.wildcardType().withUpperBounds(topre3).build());
> Type from3 = TypeUtils.parameterize(Class.class,   
> TypeUtils.parameterize(TestImpl2.class,typeVar3));
> boolean result3 = TypeUtils.isAssignable(from3, to3);
> System.out.println("from : " + from3.toString() + " : to : " + to3.toString() 
> + " : " + result3);{code}
>  
> It seems this problem occurs when it is a parameterized type class with a 
> type variable.
>  



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

Reply via email to