Skip to content

Commit 87af6df

Browse files
committed
Fix scanSuperTypes function to return Object Class instead of generic types
1 parent acc1086 commit 87af6df

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/java/org/apache/ibatis/reflection/TypeParameterResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ private static Type scanSuperTypes(TypeVariable<?> typeVar, Type srcType, Class<
206206
if (declaringClass == parentAsClass) {
207207
for (int i = 0; i < parentTypeVars.length; i++) {
208208
if (typeVar.equals(parentTypeVars[i])) {
209+
if (parentAsType.getActualTypeArguments()[i] instanceof TypeVariable<?>) {
210+
return Object.class;
211+
}
209212
return parentAsType.getActualTypeArguments()[i];
210213
}
211214
}

src/test/java/org/apache/ibatis/reflection/TypeParameterResolverTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ void testReturn_Lv2WildcardList() throws Exception {
261261
assertEquals(String.class, wildcard.getUpperBounds()[0]);
262262
}
263263

264+
@Test
265+
void testReturn_LV1Map() throws Exception {
266+
Class<?> clazz = Level1Mapper.class;
267+
Method method = clazz.getMethod("selectMap");
268+
Type result = TypeParameterResolver.resolveReturnType(method, clazz);
269+
assertTrue(result instanceof ParameterizedType);
270+
ParameterizedType paramType = (ParameterizedType) result;
271+
assertEquals(Map.class, paramType.getRawType());
272+
assertEquals(2, paramType.getActualTypeArguments().length);
273+
assertEquals(String.class, paramType.getActualTypeArguments()[0]);
274+
assertEquals(Object.class, paramType.getActualTypeArguments()[1]);
275+
}
276+
264277
@Test
265278
void testReturn_LV2Map() throws Exception {
266279
Class<?> clazz = Level2Mapper.class;

0 commit comments

Comments
 (0)