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.
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...
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...
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 :-)
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:
the important is in the following two lines:
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:
The text was updated successfully, but these errors were encountered: