On 9/19/05, [EMAIL PROTECTED] (Peter Gutmann) wrote:

>Found on the Daily WTF, http://www.thedailywtf.com/forums/43223/ShowPost.aspx:
>
>  try { 
>    int idx = 0; 
>    
>    while (true) { 
>      displayProductInfo(prodnums[idx]);
>      idx++; 
>      } 
>    } 
>  catch (IndexOutOfBoundException ex) { 
>    // nil
>    }

This is obviously just an attempt to make Java array access more like Java file 
access.  :-)

Seriously, the real flaw in this approach, which I did not see mentioned in the 
comments on the web page Peter references above, is the masking of 
IndexOutOfBoundExceptions that may be generated by displayProductInfo.  This 
code will treat such errors as "end of array".  A more normal coding of the 
loop:

    for (int i=1; i<prodnums.length; i++) { 
      displayProductInfo(prodnums[idx]);
      idx++; 
    } 

would let the exception pass up the call chain, and with good error handling, 
the problem would come to the attention of those responsible for fixing the 
program.

If ArrayIndexOutOfBoundException were used instead of IndexOutOfBoundException, 
errors in string indexing would pass up the call chain, while catching array 
problems.


Cheers - Bill

---------------------------------------------------------------------
Bill Frantz        | The first thing you need   | Periwinkle 
(408)356-8506      | when using a perimeter     | 16345 Englewood Ave
www.pwpconsult.com | defense is a perimeter.    | Los Gatos, CA 95032

---------------------------------------------------------------------
The Cryptography Mailing List
Unsubscribe by sending "unsubscribe cryptography" to [EMAIL PROTECTED]

Reply via email to