Return-Path: Delivered-To: apmail-jakarta-taglibs-dev-archive@jakarta.apache.org Received: (qmail 37630 invoked by uid 500); 9 May 2001 19:01:23 -0000 Mailing-List: contact taglibs-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: taglibs-dev@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list taglibs-dev@jakarta.apache.org Received: (qmail 36893 invoked from network); 9 May 2001 19:01:09 -0000 Received: from unknown (HELO zaphod.buildnet.com) (199.72.89.99) by h31.sny.collab.net with SMTP; 9 May 2001 19:01:09 -0000 Received: by zaphod.buildnet.com with Internet Mail Service (5.5.2653.19) id ; Wed, 9 May 2001 14:57:47 -0400 Message-ID: <93D1E7C21A1AD4119AAD00D0B73C4939010D50C1@APOLLO> From: Sean Pritchard To: "'taglibs-dev@jakarta.apache.org'" Subject: bug fix for ForTag.java Date: Wed, 9 May 2001 15:09:58 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N I downloaded the 5/9 nightly build of the utility tags and ran into a small bug with the For Tag. I was using the tag to display the elements of an array and using the array's length as input for the iterations parameter. During runtime, I happened to have a zero length array (the arrays represented results of a database search). I got an ArrayIndexOutOfBoundsException. After examining the ForTag.java code, I found that the logic had been implemented to always execute the tag body once and then check the iteration parameter. This seemed more like a do...while loop than a for loop to me. I modified the doStartTag() method to check the iteration parameter before executing the body. This solved the problem. Here is the new doStartTag() method... public int doStartTag() { if (count < getIterations()) { return EVAL_BODY_TAG; } return SKIP_BODY; } And here is the jsp page I used for testing (it will demonstrate the original error as well as the fact that it is now fixed). <%@taglib uri="/WEB-INF/utility.tld" prefix="jLib" %> <%! String [] color = new String[0]; %> Testing For with 0-length array...
    Inside For...
  • <%= color[j.intValue()] %>
Test Complete!

Counting to 10...
<%= i.intValue() %>
____________________ Sean Pritchard smpritchard@yahoo.com