Description
Circular dependencies in managed properties lead to java.lang.StackOverflowError in class org.apache.myfaces.el.VariableResolverImpl.
This can be reproduced with a simple example:
... start snippet from faces-config ...
<managed-bean>
<managed-bean-name>organisationListController</managed-bean-name>
<managed-bean-class>nl.ibgroep.demo.web.bean.controller.beheer.OrganisationListController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>organisationDetailsController</property-name>
<property-class>nl.ibgroep.demo.web.bean.controller.beheer.OrganisationDetailsController</property-class>
<value>#
</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>organisationDetailsController</managed-bean-name>
<managed-bean-class>nl.ibgroep.demo.web.bean.controller.beheer.OrganisationDetailsController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>organisationListController</property-name>
<property-class>nl.ibgroep.demo.web.bean.controller.beheer.OrganisationListController</property-class>
<value>#
</value>
</managed-property>
</managed-bean>
... end snippet from faces-config ...
If I open a page using either of these managed beans, a StackOverflowError error occurs in VariableResolverImpl.
The reason is that a new managed bean is put in scope after the complete managed bean has been created, including all dependent managed properties. So what happens is that the first managed bean (organisationListController) is created, Subsequently a new bean for its managed property (organisationDetailsController) is created. Because the first bean (organisationListController) was not put in scope, a new managed bean (organisationListController) is created, which leads to the creation of another bean (organisationDetailsController), etc.
In this simple example the cause is easy to find out, but this will be less so if the circular dependency becomes less obvious.
Solution: put the bean in scope in the ManagedBeanBuilder, before the recursive creation of its managed properties.
Attachments
Issue Links
- is duplicated by
-
MYFACES-524 It is an error to configure cyclic references between managed beans.
- Closed