commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [lang] So, about that 2.0....
Date Wed, 30 Jul 2003 21:35:06 GMT


On Wed, 30 Jul 2003, Phil Steitz wrote:

>
> > Outstanding issues:
> > - Enum tests
> > - CharSetUtils.translate(*,*,"")
>
> I have thought about the second issue some more.  Correct me if I am wrong, but
> I think that the intention of translate(str, repl, with) is:
>
> "transform str to use the with characters in place of the repl characters",
> with the understanding that if with contains fewer characters than repl, the
> last with character will be used for all of the "extra" repl characters.

Yep.

> To me, this makes no sense if either with or repl is "" or null.  In the one
> case that now throws ArrayOutOfBoundsException (repl positive length, with "")
> a case could be made that this should mean the same thing as delete(str, repl),
> but that is not obvious and I see no reason why this behavior should be
> supported in translate.
>
> Therefore, I think that the reasonable alternatives are
>
> 1. translate(str, with, repl) is a no-op (i.e. returns str unchanged) whenever
> with, repl is null or ""
>
> 2. translate(str, with, repl) throws an exception whenever with, repl is null
> or ""
>
> Personally, I like option 2 and I would rather see IllegalArgumentException
> thrown in all cases (including null).  I would also recommend modifying the
> other methods in CharSetUtils that now throw NullPointerException to throw
> IllegalArgumentException instead.  An alternative would be

This seems to always be good grounds for an argument. Sun seem to throw
NPEs instead of IAE's for a null. I think IAE makes more sense too, but
will happily accept a sun-matching style for conformity.

So... if I do:   translate("", "", ""), you're suggesting it should throw
an Exception? Or translate("foo", "", "") ?

I guess I'd expect that translate(x, y, y) would always be a do nothing
method, no exceptions etc. Even for null. If however it was:

translate("foo", null, "somethingelse")
or
translate("foo", "something", null)

I would expect NPE [or IAE].

If it was:

translate("foo", "a", "aasqqwqw")

then I'd definitely expect an IAE.

Tuppence-worth anyway :)

Hen


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message