Fix a bug where TypeParameterMatcher raises ClassCastException when an instance with raw type parameter is given
This commit is contained in:
parent
4f2e347625
commit
ed825de4bf
@ -100,8 +100,12 @@ public abstract class TypeParameterMatcher {
|
|||||||
"unknown type parameter '" + typeParamName + "': " + parameterizedSuperclass);
|
"unknown type parameter '" + typeParamName + "': " + parameterizedSuperclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type[] actualTypeParams =
|
Type genericSuperType = currentClass.getGenericSuperclass();
|
||||||
((ParameterizedType) currentClass.getGenericSuperclass()).getActualTypeArguments();
|
if (!(genericSuperType instanceof ParameterizedType)) {
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type[] actualTypeParams = ((ParameterizedType) genericSuperType).getActualTypeArguments();
|
||||||
|
|
||||||
Type actualTypeParam = actualTypeParams[typeParamIndex];
|
Type actualTypeParam = actualTypeParams[typeParamIndex];
|
||||||
if (actualTypeParam instanceof ParameterizedType) {
|
if (actualTypeParam instanceof ParameterizedType) {
|
||||||
|
@ -112,4 +112,10 @@ public class TypeParameterMatcherTest {
|
|||||||
assertFalse(m.match(new Object()));
|
assertFalse(m.match(new Object()));
|
||||||
assertTrue(m.match(new byte[1]));
|
assertTrue(m.match(new byte[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRawType() throws Exception {
|
||||||
|
TypeParameterMatcher m = TypeParameterMatcher.find(new U() { }, U.class, "E");
|
||||||
|
assertTrue(m.match(new Object()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user