diff --git a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java index b8dc32c18b..a63796f0ea 100644 --- a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java +++ b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java @@ -305,7 +305,7 @@ public abstract class GenericTypeResolver { } /** - * Extract a class instance from given Type. + * Extract a Class from the given Type. */ private static Class extractClass(Class ownerClass, Type arg) { if (arg instanceof ParameterizedType) { @@ -322,9 +322,12 @@ public abstract class GenericTypeResolver { arg = getTypeVariableMap(ownerClass).get(tv); if (arg == null) { arg = extractBoundForTypeVariable(tv); + if (arg instanceof ParameterizedType) { + return extractClass(ownerClass, ((ParameterizedType) arg).getRawType()); + } } else { - arg = extractClass(ownerClass, arg); + return extractClass(ownerClass, arg); } } return (arg instanceof Class ? (Class) arg : Object.class); diff --git a/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java b/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java index fecad196da..b2d5453c7d 100644 --- a/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java @@ -19,7 +19,6 @@ package org.springframework.core; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; - import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -27,7 +26,6 @@ import java.util.Map; import org.junit.Test; import static org.junit.Assert.*; - import static org.springframework.core.GenericTypeResolver.*; import static org.springframework.util.ReflectionUtils.*; @@ -79,7 +77,6 @@ public class GenericTypeResolverTests { */ @Test public void genericMethodReturnTypes() { - Method notParameterized = findMethod(MyTypeWithMethods.class, "notParameterized", new Class[] {}); assertEquals(String.class, resolveReturnTypeForGenericMethod(notParameterized, new Object[] {})); @@ -156,6 +153,11 @@ public class GenericTypeResolverTests { assertEquals(Integer[].class, resolveType(genericArrMessageMethodParam.getGenericParameterType(), varMap)); } + @Test + public void testBoundParameterizedType() { + assertEquals(B.class, resolveTypeArgument(TestImpl.class, ITest.class)); + } + public interface MyInterfaceType { } @@ -273,4 +275,13 @@ public class GenericTypeResolverTests { static class GenericClass { } + class A{} + + class B{} + + class ITest{} + + class TestImpl> extends ITest{ + } + }