Bug 9946 - for tag does iterate even if iterations are given as 0
Summary: for tag does iterate even if iterations are given as 0
Status: CLOSED WONTFIX
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Unknown Taglib (show other bugs)
Version: 1.0
Hardware: All All
: P3 critical with 3 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-18 08:39 UTC by sachin
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sachin 2002-06-18 08:39:22 UTC
iterations property in for tag is not checked at the start of the tag. Thus, if begin value is 0 and 
number of iterations is 0 still the tag gets executed once. This leads to index out of bounds 
exceptions in some situations. This needs to be checked in start tag. 


    public int 
doStartTag() {
        if ( iterations > 0 )
        {
            return EVAL_BODY_TAG;
        }
        else
        {
            return 
SKIP_BODY;
        }
    }

Simillarly in IF tag the java scriptlets get executed for both then and 
else parts and only html part is not displayed.  This is not intended the body should be skipped at 
the start only as nothing should be excuted in else tag / in if tag depending on condition.

Thus 
in IFThenTag it is necessary to do following :
        if( ! parent.getCondition() )
        {
            return 
SKIP_BODY;
        }

Similarly in IFElse Tag :
        if( parent.getCondition() )
        {
            return 
SKIP_BODY;
        }

Hope this helps.

Regards,
Sachin
Comment 1 Glenn Nielsen 2002-12-01 22:49:20 UTC
The utility taglib is deprecated. It was only an example tag library.
Thanks for submitting the patch.