Menu

#22 OptionList null safe

open
nobody
None
5
2008-05-08
2008-05-08
Andy
No

Hello,

do you think it is a good idea to make OptionList accept null values?

I tried to use it with null values but in method indexOfValue it crashes:

public int indexOfValue (String value)
{
int numChildren = DOM.getChildCount(getElement());
for (int i = 0; i < numChildren; i++) {
if (getValue(i).equals(value)) {
return i;
}
}
return -1;
}

getValue(i) is null and so equals is not possible.

it could be fixed with:

String ithValue = getValue(i);
if (ithValue != null && ithValue.equals(value)
|| ithValue == value) {
return i;
}

Regards

Andreas

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.