Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.14.0
-
None
-
None
Description
TypeUtils.isAssignable returns a wrong result for ParameterizedType when raw class is "Class".
Given class definitions as following, for example,
class TestIF<T> { } class TestImpl<T> extends TestIF<T> { } class TestImpl2<R> extends TestIF<Number> { }
Java compile error occurs as in the case below.
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
but the isAssignable() returns true. it should be false.
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);
It seems this problem occurs when it is a parameterized type class with a type variable.