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

jinwoo choi edited comment on LANG-1749 at 8/21/24 1:02 AM:
------------------------------------------------------------

[~ggregory] 
The results of debugging based on 3.16.0 for the 1st example were as follows.
 - 1st example
{code:java}
Class<? extends TestIF<?>> a1 = null;
Class<TestIF> b1 = null;
a1 = b1; //compile error
{code}

 - 1st example test code
{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);
{code}

 - debugging point 
|method|type|toType|line|
|TypeUtils.isAssignable(ParameterizedType)|Class<TestIF<T>>|Class<? extends 
TestIF<?>>|1179 line|
|TypeUtils.isAssignable(WildcardType)|TestIF<T>|? extends TestIF<?>|1341 line|
|TypeUtils.isAssignable(ParameterizedType)|TestIF<T>|TestIF<?>|1179 line|
|TypeUtils.isAssignable(WildcardType)|T|?|1021 line|
|TypeUtils.isAssignable(Class<?>)|Object|Object|1002 line|

 

I believe that the current code, which returns true when the type is 
TypeVariable and toType is Wildcard ?, should be improved, as shown in row 4 of 
the table above. 
Please let me know your opinion.


was (Author: JIRAUSER306394):
[~ggregory] 
The results of debugging based on 3.16.0 for the 1st example were as follows.

- 1st example
Class<? extends TestIF<?>> a1 = null;Class<TestIF> b1 = null;
a1 = b1; //compile error
- 1st example test code
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);
- debugging 
|method|type|toType|line|
|TypeUtils.isAssignable(ParameterizedType)|Class<TestIF<T>>|Class<? extends 
TestIF<?>>|1179 line|
|TypeUtils.isAssignable(WildcardType)|TestIF<T>|? extends TestIF<?>|1341 line|
|TypeUtils.isAssignable(ParameterizedType)|TestIF<T>|TestIF<?>|1179 line|
|TypeUtils.isAssignable(WildcardType)|T|?|1021 line|
|TypeUtils.isAssignable(Class<?>)|Object|Object|1002 line|

 

I believe that the current code, which returns true when the type is 
TypeVariable and toType is Wildcard ?, should be improved, as shown in row 4 of 
the table above. 
Please let me know your opinion.

> 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
>
> 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