jinwoo choi created LANG-1749:
---------------------------------
Summary: 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
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<String> {
} {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}
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, TestIF.class);
boolean result1 = TypeUtils.isAssignable(from1, to1);
System.out.println("from : " + from1.toString() + " : to : " + to1.toString() +
" : " + result1);
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, TestImpl.class);
boolean result2 = TypeUtils.isAssignable(from2, to2);
System.out.println("from : " + from2.toString() + " : to : " + to2.toString() +
" : " + result2);
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, TestImpl2.class);
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)