diff --git a/src/main/java/org/apache/ibatis/reflection/TypeParameterResolver.java b/src/main/java/org/apache/ibatis/reflection/TypeParameterResolver.java index ef1c1da0732..3a7dddcbfed 100644 --- a/src/main/java/org/apache/ibatis/reflection/TypeParameterResolver.java +++ b/src/main/java/org/apache/ibatis/reflection/TypeParameterResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * 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< if (declaringClass == parentAsClass) { for (int i = 0; i < parentTypeVars.length; i++) { if (typeVar.equals(parentTypeVars[i])) { - return parentAsType.getActualTypeArguments()[i]; + Type actualType = parentAsType.getActualTypeArguments()[i]; + return actualType instanceof TypeVariable ? Object.class : actualType; } } } diff --git a/src/test/java/org/apache/ibatis/reflection/TypeParameterResolverTest.java b/src/test/java/org/apache/ibatis/reflection/TypeParameterResolverTest.java index d8b4760f219..7a16f2e8574 100644 --- a/src/test/java/org/apache/ibatis/reflection/TypeParameterResolverTest.java +++ b/src/test/java/org/apache/ibatis/reflection/TypeParameterResolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -261,6 +261,19 @@ void testReturn_Lv2WildcardList() throws Exception { assertEquals(String.class, wildcard.getUpperBounds()[0]); } + @Test + void testReturn_LV1Map() throws Exception { + Class clazz = Level1Mapper.class; + Method method = clazz.getMethod("selectMap"); + Type result = TypeParameterResolver.resolveReturnType(method, clazz); + assertTrue(result instanceof ParameterizedType); + ParameterizedType paramType = (ParameterizedType) result; + assertEquals(Map.class, paramType.getRawType()); + assertEquals(2, paramType.getActualTypeArguments().length); + assertEquals(String.class, paramType.getActualTypeArguments()[0]); + assertEquals(Object.class, paramType.getActualTypeArguments()[1]); + } + @Test void testReturn_LV2Map() throws Exception { Class clazz = Level2Mapper.class;