Bug 38197 - taglib pool bug when tag is used with jsp:attribute
Summary: taglib pool bug when tag is used with jsp:attribute
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 5.5.12
Hardware: PC Windows Vista
: P2 major with 1 vote (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2006-01-09 15:53 UTC by Diego Belfer
Modified: 2009-06-03 15:12 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Diego Belfer 2006-01-09 15:53:09 UTC
When i use a taglib twice in the same page and the two instances of these tags 
share the same atrributes in the declaration but one of them have and attribute
set using jsp:attribute, the value of this attribute is used in the other one too.

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<h4>1 to 10 step 2</h4>
<c:forEach var="i" begin="1" end="10">
<jsp:attribute name="step">2</jsp:attribute>
  <c:out value="${i}"/> 
<h4>1 to 10 no step</h4>
<c:forEach var="i" begin="1" end="10" >
  <c:out value="${i}"/> 

The output is 

Simple Range Iteration
1 to 10 step 2
1 3 5 7 9
1 to 10 no step
1 3 5 7 9

Simple Range Iteration
1 to 10 step 2
1 3 5 7 9
1 to 10 no step
1 2 3 4 5 5 7 8 9

Comment 2 Diego Belfer 2007-12-05 10:16:51 UTC
Well it has been a while since I reported this.  I am not sure the current
status of the implementation right now. At the time I checked the code, there
was a bug in the way of picking the pooled instance, and since it was closed as
invalid I will assume it was not fixed.

From the JSP spec:
"The JSP container may reuse classic tag handler instances for multiple
occurrences of the corresponding custom action, in the same page or in different
pages, but only if the same set of attributes are used for all occurrences. If a
tag handler is used for more than one occurence, the container must reset all
attributes where the values differ between the custom action occurrences. If an
attribute value is set as a request-time attribute value (using a scripting or
an EL expression), the container must reset the attribute between all reuses of
the tag handler instance ..."

The pool implementation is using attributes specified in the basic way for
selecting a pooled instance. I mean:

<mytag attr="1"/>

But it is not considering the alternate way of specifying an attribute

<jsp:attribute name="attr">1</jsp:attribute>

From the spec:
"The <jsp:attribute> action must only be used to specify an attribute value for
standard or custom actions."

So <jsp:attribute> is valid way of specifying an attribute for a custom action
and TagLibs are actions, therefore, the container should use attributes defined
by this mean when selecting the pooled instance.

In the example code I posted originally (when I reported the bug), the same
instance of the TagHandler is used, and although the attributes set differs,
those attributes are not reset as the specification states.
For the way the pool is implemented, a different instance should be used because
an additional attribute is specified.

As a conclusion, if a properly developed TagHandler is used and one of its
attributes is specified using <jsp:attribute>, which is completely valid, the
obtained result could be wrong due to the way the Pool is implemented.
Comment 3 Mark Thomas 2009-02-04 02:28:53 UTC
Thanks for the report. I have fixed this in trunk and proposed the fix for 6.0.x and 5.5.x
Comment 4 Mark Thomas 2009-02-20 14:46:20 UTC
This has been fixed in 6.0.x and will be included in 6.0.19 onwards
Comment 5 Mark Thomas 2009-06-03 15:12:33 UTC
This has been fixed in 5.5.x and will be included in 5.5.28 onwards.