Menu

#274 Out of Bounds Exception should be avoided

closed-fixed
None
5
2008-04-01
2005-02-16
No

An out of boundx exception
java.lang.ArrayIndexOutOfBoundsException: 0
at
com.meterware.httpunit.SelectionFormControl$Options.get(FormControl.j
ava:1293)

is possible Since
public Object get( int index ) {
return _options[ index ];
}

does not check whether the index is valid.
I think:
public Object get( int index ) {
if (index < 0 || index >= _options.length) {
String msg="invalid index "+index+" for
Options ";
for (int i = 0; i < _options.length; i++) {
msg=msg+(_options[i]._text);
if (i>0)
msg=msg+",";
}
throw new RuntimeException(msg);
}
return _options[ index ];
}

would be an improvement
For empty options you now get:
java.lang.RuntimeException: invalid index 0 for Options

when the options are available they would be listed

Discussion

  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-01

    Logged In: YES
    user_id=1220573
    Originator: YES

    version 868 has an improved version with test

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-01

    Logged In: YES
    user_id=1220573
    Originator: YES

    The change is now in the subversion repository and will be in the next build

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-01
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> closed
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-01
    • status: closed --> closed-fixed
     

Log in to post a comment.