OddProblems
OddProblems

Reputation: 201

JSF - MyFaces - Stack Overflow Error

I am receiving a StackOverflowError while rendering a JSF page. It happens after loading a particular set of data (which happens successfully) and then doing anything else on the page. Note that the page will load properly if it is refreshed after the error occurs. The page works perfectly otherwise and is able to load more records than are loaded in the error condition.

Depending on the steps taken, the error message can vary slightly but the error will always appear.

I am using MyFaces 1.2 (cannot be upgraded at this point).

Is this a common issue with a solution?

Example 1:

java.lang.StackOverflowError
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:947)
at java.lang.ClassLoader.loadClass(ClassLoader.java:291)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
at weblogic.utils.classloaders.FilteringClassLoader.findClass(FilteringClassLoader.java:101)
at weblogic.utils.classloaders.FilteringClassLoader.loadClass(FilteringClassLoader.java:86)
at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:45)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
at com.sun.el.parser.AstIdentifier.getValue(Unknown Source)
at com.sun.el.parser.AstDeferredExpression.getValue(Unknown Source)
at com.sun.el.parser.AstCompositeExpression.getValue(Unknown Source)
at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
     ...

Example2:

java.lang.StackOverflowError
at javax.el.ELContext.(ELContext.java:222)
at com.sun.el.lang.EvaluationContext.(Unknown Source)
at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
at com.sun.el.parser.AstIdentifier.getValue(Unknown Source)
at com.sun.el.parser.AstDeferredExpression.getValue(Unknown Source)
at com.sun.el.parser.AstCompositeExpression.getValue(Unknown Source)
at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
     ...

Update: I have fixed the problem. There was a problem in the standard header code - it didn't like all of the parameters. I didn't write the failing code below but I'll have to fix it. Checking the stack in Eclipse (when the StackOverflowError breakpoint was hit), it cycled between the (a) line and (b) line (which both hit TagValueExpression.getValue(..)).

<c:forEach var="attr" items="#{request.parameterMap}">
                            <c:if test="#{empty flag}">
                            (a)    <c:set var="parameters" value="#{parameters}&amp;"/>
                            </c:if>
                            <c:set var="flag" value=""/>
                            (b)<c:set var="parameters" value="#{parameters}#{attr.key}=#{attr.value[0]}"/>
                        </c:forEach>

Upvotes: 2

Views: 1525

Answers (1)

BalusC
BalusC

Reputation: 1108722

java.lang.StackOverflowError
    ...
    at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
    at com.sun.el.parser.AstIdentifier.getValue(Unknown Source)
    at com.sun.el.parser.AstDeferredExpression.getValue(Unknown Source)
    at com.sun.el.parser.AstCompositeExpression.getValue(Unknown Source)
    at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
    at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
    ...

So, some EL expression is referencing to itself and thus running in an infinite recursion loop, causing a stack overflow.

Here is one of the most common causes which should be simple enough to understand the problem:

<h:inputText binding="#{input}" value="#{input.value}" />

In the above example, the #{input} refers to the component itself. The #{input.value} refers to the value attribute. But if you use it in the value attribute itself, then this keeps back-referencing the value attribute in an infinite recursion loop. In such case, you'd need to fix it by binding the value to a fullworthy managed bean property instead.

Check your pages for this kind of logic mistakes. It by the way doesn't matter if the component is bound to a managed bean or not, it would fail as good:

<h:inputText binding="#{bean.input}" value="#{bean.input.value}" />

You should then be using

<h:inputText binding="#{bean.input}" value="#{bean.value}" />

Or maybe just this

<h:inputText binding="#{bean.input}" />

Or even just this, depending on the concrete functional requirement

<h:inputText value="#{bean.value}" />

Upvotes: 3

Related Questions