Bug 40870

Summary: Tag 'out' incorrectly handles variable 'param'
Product: Taglibs Reporter: aklimuk
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 1.1   
Target Milestone: ---   
Hardware: PC   
OS: other   
Attachments: test.jsp

Description aklimuk 2006-11-02 02:47:11 UTC
If loop variable is named 'param', tag 'out' evaluates it to EMPTY string.
If loop variable has any other name, it is processed correctly.

Example 1. Incorrect processing.
	<c:forEach items="${cols}" var="param">
		<c:out value="${param.name}"/><br>

Example 2. Correct processing.
	<c:forEach items="${cols}" var="col">
		<c:out value="${col.name}"/><br>

Example 3. Correct processing. This is modified Example 1.
	<c:forEach items="${cols}" var="param">
		<c:out value="${pageScope.param.name}"/><br>

I checked the code in debugger. In all cases 'pageContext' contains attribute with correct name. E.g. in Example 1, 'pageContext' contains an attribute 'param' with correct value.

The same problem exists if <c:forEach> is replaced by <logic:iterate>.

Other tags work correctly in this case. E.g. following code works correctly:
	<c:forEach items="${cols}" var="param">
                <html:text name="param" property="name"/><br>

So, the problem is somewhere inside 'out'.
Comment 1 aklimuk 2006-11-02 02:50:26 UTC
Created attachment 19069 [details]

For simplicity, this JSP contains definition of bean class used in the
described examples.
Comment 2 Henri Yandell 2006-11-06 12:22:31 UTC
Is this with the JSTL 1.1.2 release?

Looking at the source, I don't see the word 'param' mentioned, which is odd as
you'd expect either the Out of the ForEach code to mention 'param' somewhere for
this bug to be happening.
Comment 3 Rahul Akolkar 2006-11-06 12:31:37 UTC
'param' is an implicit JSP variable (map of HTTP request parameters), and IMO, 
its best to not step over implicit variables by re-defining them in any scope 
(choose a different variable name)
Comment 4 Henri Yandell 2006-11-06 17:16:21 UTC
Thanks Rahul - I'm very rusty :)
Comment 5 aklimuk 2006-11-08 01:31:00 UTC
(In reply to comment #3)
> 'param' is an implicit JSP variable (map of HTTP request parameters), and IMO, 
> its best to not step over implicit variables by re-defining them in any scope 
> (choose a different variable name)

You are right, 'param' is am implicit EL variable. But despite this, tags 'forEach' and 'iterate' correctly create the loop variable 'param' and correctly place it to the page context. While looping, this variable is correctly changed. Besides, the tag 'html:text' correctly retrieves variable 'param' from the page context and correctly processes it.

So why these three tags correctly process 'param' variable, but 'out' doesn't?
This seems to be an inconsistency. Why some tags process 'param' in one way, some - in another way? Either NONE of tags should process 'param' as local variable, or ALL of them should process it in the same way.
Comment 6 Henri Yandell 2007-01-03 16:25:44 UTC
The loop isn't necessary, the following confirms the bug:

<c:set var="param" value="52"/>
<c:out value="${pageScope.param}"/><br/>
<c:out value="${param}"/><br/>
Comment 7 Henri Yandell 2007-01-03 16:40:00 UTC
Digging into it, my gut feel is that it's due to line 70 of
org/apache/taglibs/standard/lang/jstl/JSTLVariableResolver.java. It also
suggests that the same problem will exist for:


Testing 'header', it's got the same problem.

I think it's not worth the time to try and rewrite this so that things can work
for some of them in certain contexts and not for other ones. 
So we should FAQ this and point out the pageScope workaround.
Comment 8 Henri Yandell 2007-01-29 17:10:26 UTC
Added to the FAQ:


Resoling WONTFIX.