Skip to content

Commit e7f3493

Browse files
committed
Merge pull request #34086 from rPraml
* pr/34086: Polish "Resolve base type in parameterized type if necessary" Resolve base type in parameterized type if necessary Closes gh-34086
2 parents 2273850 + fe5f5d5 commit e7f3493

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -180,7 +180,7 @@ else if (genericType instanceof ParameterizedType parameterizedType) {
180180
generics[i] = resolvedTypeArgument;
181181
}
182182
else {
183-
generics[i] = ResolvableType.forType(typeArgument);
183+
generics[i] = ResolvableType.forType(typeArgument).resolveType();
184184
}
185185
}
186186
else if (typeArgument instanceof ParameterizedType) {

spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -211,6 +211,14 @@ void resolveNestedTypeVariable() throws Exception {
211211
assertThat(ResolvableType.forType(resolved).getGeneric(0).getGeneric(0).resolve()).isEqualTo(String.class);
212212
}
213213

214+
@Test
215+
void resolvedTypeWithBase() {
216+
Type type = method(WithBaseTypes.class, "get").getGenericReturnType();
217+
Type resolvedType = resolveType(type, WithBaseTypes.class);
218+
ParameterizedTypeReference<List<A>> reference = new ParameterizedTypeReference<>() {};
219+
assertThat(resolvedType).isEqualTo(reference.getType());
220+
}
221+
214222
private static Method method(Class<?> target, String methodName, Class<?>... parameterTypes) {
215223
Method method = findMethod(target, methodName, parameterTypes);
216224
assertThat(method).describedAs(target.getName() + "#" + methodName).isNotNull();
@@ -398,4 +406,12 @@ public interface ListOfListSupplier<T> {
398406
public interface StringListOfListSupplier extends ListOfListSupplier<String> {
399407
}
400408

409+
static class WithBaseTypes {
410+
411+
<T extends A> List<T> get() {
412+
return List.of();
413+
}
414+
415+
}
416+
401417
}

0 commit comments

Comments
 (0)