From 8d23079742fab9d4a27287d46ec71f9d89aceec2 Mon Sep 17 00:00:00 2001 From: arimu1 <19286898+arimu1@users.noreply.github.com> Date: Sat, 22 Aug 2026 11:28:59 +0700 Subject: [PATCH] Collect nested generic arguments when resolving type signatures. `TypeUtils.resolveTypesInSignature` skipped nested arguments of a raw type that was already seen, so `V` in `Map>` was missing from the AOT type set. Closes #3530 Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com> --- .../springframework/data/util/TypeUtils.java | 14 +++++++--- .../data/aot/TypeCollectorUnitTests.java | 7 +++++ .../data/aot/types/NestedGenericMaps.java | 27 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/springframework/data/aot/types/NestedGenericMaps.java diff --git a/src/main/java/org/springframework/data/util/TypeUtils.java b/src/main/java/org/springframework/data/util/TypeUtils.java index 1cbd40a973..8109861cf5 100644 --- a/src/main/java/org/springframework/data/util/TypeUtils.java +++ b/src/main/java/org/springframework/data/util/TypeUtils.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.Collection; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Stream; @@ -37,6 +38,7 @@ /** * @author Christoph Strobl + * @author arimu1 */ // TODO: Consider moving to the org.springframework.data.util package or make this package-private if not used somewhere // else. @@ -159,21 +161,25 @@ public static Set> resolveTypesInSignature(ResolvableType root) { } private static void resolveTypesInSignature(ResolvableType current, Set> signatures) { + resolveTypesInSignature(current, signatures, new HashSet<>()); + } + + private static void resolveTypesInSignature(ResolvableType current, Set> signatures, Set visited) { if (ResolvableType.NONE.equals(current) || ObjectUtils.nullSafeEquals(Void.TYPE, current.getType()) || ObjectUtils.nullSafeEquals(Object.class, current.getType())) { return; } - if (signatures.contains(current.toClass())) { + if (!visited.add(current.toString())) { return; } signatures.add(current.toClass()); - resolveTypesInSignature(current.getSuperType(), signatures); + resolveTypesInSignature(current.getSuperType(), signatures, visited); for (ResolvableType type : current.getGenerics()) { - resolveTypesInSignature(type, signatures); + resolveTypesInSignature(type, signatures, visited); } for (ResolvableType type : current.getInterfaces()) { - resolveTypesInSignature(type, signatures); + resolveTypesInSignature(type, signatures, visited); } } diff --git a/src/test/java/org/springframework/data/aot/TypeCollectorUnitTests.java b/src/test/java/org/springframework/data/aot/TypeCollectorUnitTests.java index 315116363a..7472b3fa43 100644 --- a/src/test/java/org/springframework/data/aot/TypeCollectorUnitTests.java +++ b/src/test/java/org/springframework/data/aot/TypeCollectorUnitTests.java @@ -29,6 +29,7 @@ * * @author Christoph Strobl * @author Mark Paluch + * @author arimu1 */ public class TypeCollectorUnitTests { @@ -99,4 +100,10 @@ void typeFilterReflectsAdditionalTypeFilters() { assertThat(TypeCollector.inspect(c -> c.filterTypes(cls -> false), FieldsAndMethods.class).list()).isEmpty(); } + @Test // GH-3530 + void detectsTypesNestedMoreThanOneGenericLevel() { + assertThat(TypeCollector.inspect(NestedGenericMaps.class).list()).contains(NestedGenericMaps.class, + EmptyType1.class, EmptyType2.class); + } + } diff --git a/src/test/java/org/springframework/data/aot/types/NestedGenericMaps.java b/src/test/java/org/springframework/data/aot/types/NestedGenericMaps.java new file mode 100644 index 0000000000..6e2d033e20 --- /dev/null +++ b/src/test/java/org/springframework/data/aot/types/NestedGenericMaps.java @@ -0,0 +1,27 @@ +/* + * Copyright 2026 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.aot.types; + +import java.util.Map; + +/** + * @author arimu1 + */ +public class NestedGenericMaps { + + Map one; + Map> two; +}