What about this case:
public static int indexOfAny(String str, String[] searchStrs) {
if ((str == null) || (searchStrs == null)) {
return -1;
}
int sz = searchStrs.length;
// String's can't have a MAX_VALUEth index.
int ret = Integer.MAX_VALUE;
int tmp = 0;
for (int i = 0; i < sz; i++) {
tmp = str.indexOf(searchStrs[i]);
if (tmp == -1) {
continue;
}
if (tmp < ret) {
ret = tmp;
}
}
This throws a NullPointerException. Should we convert that to an IAE?
Also, this is a case of 'fixing' the standard Java library.
String.indexOf(String str) will throw a NPE if str is null. [That's where
indexOfAny will throw] It also can't be called on a null string.
I'm not saying there isn't a place for 'safe' APIs. But, in my opinion, they
should be an alternative, not the default.
On Thursday 26 September 2002 08:14 pm, Steven Caswell wrote:
> My opinion, in this order:
> +1 on silent handling of null
> +1 on throwing IAE if silent handling doesn't make sense
> -1 on throwing NPE
>
>
> Steven Caswell
> [EMAIL PROTECTED]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>