-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeDescriptor
with recursive generics triggers infinite recursion in ResolvableType.equals/hashCode
#33932
Comments
TypeDefinition
TypeDefinition
TypeDescriptor
Hi @juancarrey, Congratulations on submitting your first issue for the Spring Framework! 👍 Unfortunately you have not provided enough information for us to reproduce the issue. If you would like us to investigate this, please provide a minimal example that we can run -- for example, a stand-alone JUnit test class or a minimal sample application made available via a Git repository or a ZIP file attached to this issue. Thanks In any case, it appears that this may be an issue with |
Indeed, the following results in a class RecursiveTypeDescriptorTests {
@Test
void recursiveTypeDescriptor() {
TypeDescriptor typeDescriptor1 =
TypeDescriptor.map(Map.class,
TypeDescriptor.valueOf(String.class),
TypeDescriptor.valueOf(RecursiveMap.class));
TypeDescriptor typeDescriptor2 =
TypeDescriptor.map(Map.class,
TypeDescriptor.valueOf(String.class),
TypeDescriptor.valueOf(RecursiveMap.class));
assertThat(typeDescriptor1).isEqualTo(typeDescriptor2);
}
static class RecursiveMap extends HashMap<String, RecursiveMap> {
}
} That results in a stack trace like this:
But if we change the declaration of static class RecursiveMap extends HashMap<String, RecursiveMap>
implements Map<String, RecursiveMap> {
} ... we then see a stack trace like this:
Note the recursion in |
We like to avoid infinite recursion in such scenarios, potentially by checking upfront if the generics are equal without recursing, or potentially by tracking which types have been visited and throwing an exception if a cycle is detected. Tentatively assigned to Note: there might be recursion issues in |
TypeDescriptor
equals()
and hashCode()
in recursive TypeDescriptor
equals()
and hashCode()
in recursive TypeDescriptor
equals()
and hashCode()
for ResolvableType
with recursive generics
Hi, I used the code in your comment to try to analyze the cause of this problem.
|
equals()
and hashCode()
for ResolvableType
with recursive genericsTypeDescriptor
triggers infinite recursion in equals()
and hashCode()
for ResolvableType
with recursive generics
TypeDescriptor
triggers infinite recursion in equals()
and hashCode()
for ResolvableType
with recursive genericsTypeDescriptor
with recursive generics triggers infinite recursion in ResolvableType.equals/hashCode
During SpEL evaluation, if the
TypeDescriptor
is recursive, the evaluation results in infinite recursion causing stack overflow.This line:
spring-framework/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
Line 509 in ba4105d
Evaluated object sample where we have this issue is a map:
This causes the evaluation of equality to check the type, and recursively the inner types of the map.
The text was updated successfully, but these errors were encountered: