Skip to content

Commit 5bd8cb5

Browse files
authored
Merge pull request #3150 from yuanjin5/fixbug
Fix scanSuperTypes function to return Object Class instead of generic types
2 parents 46cd8e6 + 8fb229e commit 5bd8cb5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -206,7 +206,8 @@ 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-
return parentAsType.getActualTypeArguments()[i];
209+
Type actualType = parentAsType.getActualTypeArguments()[i];
210+
return actualType instanceof TypeVariable<?> ? Object.class : actualType;
210211
}
211212
}
212213
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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)