Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/org/springframework/data/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -159,21 +161,25 @@ public static Set<Class<?>> resolveTypesInSignature(ResolvableType root) {
}

private static void resolveTypesInSignature(ResolvableType current, Set<Class<?>> signatures) {
resolveTypesInSignature(current, signatures, new HashSet<>());
}

private static void resolveTypesInSignature(ResolvableType current, Set<Class<?>> signatures, Set<String> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author arimu1
*/
public class TypeCollectorUnitTests {

Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<String, EmptyType1> one;
Map<String, Map<String, EmptyType2>> two;
}
Loading