Fix a bug where TypeParameterMatcher raises ClassCastException when an instance with raw type parameter is given

This commit is contained in:
Trustin Lee 2013-03-09 09:19:34 +09:00
parent 4f2e347625
commit ed825de4bf
2 changed files with 12 additions and 2 deletions

View File

@ -100,8 +100,12 @@ public abstract class TypeParameterMatcher {
"unknown type parameter '" + typeParamName + "': " + parameterizedSuperclass);
}
Type[] actualTypeParams =
((ParameterizedType) currentClass.getGenericSuperclass()).getActualTypeArguments();
Type genericSuperType = currentClass.getGenericSuperclass();
if (!(genericSuperType instanceof ParameterizedType)) {
return Object.class;
}
Type[] actualTypeParams = ((ParameterizedType) genericSuperType).getActualTypeArguments();
Type actualTypeParam = actualTypeParams[typeParamIndex];
if (actualTypeParam instanceof ParameterizedType) {

View File

@ -112,4 +112,10 @@ public class TypeParameterMatcherTest {
assertFalse(m.match(new Object()));
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()));
}
}