Skip to content
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

Autowiring of Generic Types - StackOverflowError ResolvableType.isAssignableFrom(ResolvableType.java:259) [SPR-11522] #16147

Closed
spring-projects-issues opened this issue Mar 6, 2014 · 6 comments
Assignees
Labels
in: core type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 6, 2014

Dumitru Boldureanu opened SPR-11522 and commented

I'm experiencing what seems to be a spring 4.0 bug related to the new feature "Autowiring of Generic Types".

Getting a java.lang.StackOverflowError when trying to inject a generic dao:

public interface StockMovementDao<S extends StockMovement>

the important is in the following two lines:

public interface StockMovement<P extends StockMovementInstruction>
public interface StockMovementInstruction<C extends StockMovement>

Please note that one uses the other as generic parameter - StockMovement uses StockMovementInstruction and StockMovementInstruction the StockMovement.

Because of that org.springframework.core.ResolvableType.isAssignableFrom(ResolvableType.java:259) is called for one then for the other infinitely till a StackOverflowError.

I guess that to fix this bug, A.isAssignableFrom(B) -> B.isAssignableFrom(A) cases should be detected. I might be wrong, but in these cases it should probably return true.


Affects: 4.0 GA, 4.0.1, 4.0.2

Attachments:

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 6, 2014

Juergen Hoeller commented

Fixed through detection of pre-checked types when recursing.

This will be available in the next 4.0.3 snapshot (see http://projects.spring.io/spring-framework/ for Maven coordinates). Please give it a try and let us know whether it works for you...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 11, 2014

Dumitru Boldureanu commented

Tested the code in snapshot.
The modification fixed the issue in several situations/cases, but not for all. In short there is a loop created:
"main"
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:725)
org.springframework.core.ResolvableType.access$100(ResolvableType.java:79)
org.springframework.core.ResolvableType$DefaultVariableResolver.resolveVariable(ResolvableType.java:1200)
org.springframework.core.ResolvableType.resolveType(ResolvableType.java:705)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:725)
org.springframework.core.ResolvableType.access$100(ResolvableType.java:79)
org.springframework.core.ResolvableType$DefaultVariableResolver.resolveVariable(ResolvableType.java:1200)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:741)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:725)
org.springframework.core.ResolvableType.access$100(ResolvableType.java:79)
org.springframework.core.ResolvableType$DefaultVariableResolver.resolveVariable(ResolvableType.java:1200)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:741)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:725)
org.springframework.core.ResolvableType.access$100(ResolvableType.java:79)
org.springframework.core.ResolvableType$DefaultVariableResolver.resolveVariable(ResolvableType.java:1200)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:741)
org.springframework.core.ResolvableType.resolveVariable(ResolvableType.java:725)
etc...

Building a test project...

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 12, 2014

Dumitru Boldureanu commented

Attached another test project(SPR-issue-2.zip), which fails with 4.0.3.BUILD-SNAPSHOT

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 12, 2014

Dumitru Boldureanu commented

The modification fixed the issue in several situations/cases, but not for all.
Added another test project.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 13, 2014

Juergen Hoeller commented

Fixed through checking the raw Type objects, not the ResolvableType instances, during isAssignableFrom's recursion. This catches circular type variables with constantly changing type resolution context but nevertheless pointing to the same underlying variables.

To be available in the upcoming 4.0.3 snapshot. Try to break it again please :-)

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 17, 2014

Dumitru Boldureanu commented

Thank you,
Everything loads properly now :)

@spring-projects-issues spring-projects-issues added type: bug in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.0.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants