Bug 9946

Summary: for tag does iterate even if iterations are given as 0
Product: Taglibs Reporter: sachin <sachinsah>
Component: Unknown TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: CLOSED WONTFIX    
Severity: critical    
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: All   
OS: All   

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.