Bug 59668 - x:forEach retains the incorrect scope when used in a tag called from another x:forEach
Summary: x:forEach retains the incorrect scope when used in a tag called from another ...
Status: NEW
Alias: None
Product: Taglibs
Classification: Unclassified
Component: XTags Taglib (show other bugs)
Version: unspecified
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2016-06-06 20:52 UTC by Matthew Casperson
Modified: 2016-06-06 20:52 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Casperson 2016-06-06 20:52:17 UTC
This is related to https://github.com/mcasperson/wildfly_jstl_bug/

There is a bug that occurs when you have a x:forEach in a JSP page, and inside this x:forEach you call a tag that itself has a x:forEach. The variable created by the second x:forEach is inaccessible to any nested x:out elements.

This happens because the x:out pagecontext is assigned from the parent x:forEach (from the tag file), which in turn has its pageContext assigned from its parent x:forEach (from the JSP page). This means the x:out element has no access to page scoped variables from the tag.

This bug is known to affect WildFly 10.0.0, which uses code forked from the Apache TagLib project. See https://github.com/mcasperson/wildfly_jstl_bug/blob/master/src/main/webapp/index.jsp and https://github.com/mcasperson/wildfly_jstl_bug/blob/master/src/main/webapp/WEB-INF/tags/my.tag for more details. When run, this JSP page produces the exception:

Caused by: javax.xml.transform.TransformerException: Could not resolve XPath variable: $childNode
            at org.apache.taglibs.standard.tag.common.xml.JSTLVariableStack.getVariableOrParam(JSTLVariableStack.java:93)
            at org.apache.xpath.operations.Variable.execute(Variable.java:219)
            at org.apache.xpath.operations.Variable.execute(Variable.java:188)
            at org.apache.xpath.axes.FilterExprIteratorSimple.executeFilterExpr(FilterExprIteratorSimple.java:116)
            at org.apache.xpath.axes.FilterExprWalker.setRoot(FilterExprWalker.java:131)
            at org.apache.xpath.axes.WalkingIterator.setRoot(WalkingIterator.java:157)
            at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:265)
            at org.apache.xpath.axes.LocPathIterator.execute(LocPathIterator.java:212)
            at org.apache.xpath.XPath.execute(XPath.java:337)
            ... 41 more

We have a fix which you can view at https://github.com/jboss/jboss-jstl-api_spec/pull/12/files/e0b0140c879c43c8dc2cc881e5cd3d857935d685..b03bea7ad4d3a92a16d8a9f67434cf033f72ca09. It is a nasty hack so I am not suggesting this is how the problem should be solved, but it does demonstrate how pageContexts are being incorrectly assigned with the x:forEach element and nested tags.