Please review: surrogate fiddle (original) (raw)

Ulf Zibis Ulf.Zibis at CoSoCo.de
Thu Mar 21 12:56:11 UTC 2013


Am 21.03.2013 00:22, schrieb Martin Buchholz:

AbstractStringBuilder:
Instead
  270     public int codePointBefore(int index) {
  271         int i = index - 1;
  272         if ((i < 0) || (i >= count)) {
  273             throw new StringIndexOutOfBoundsException(index);
  274         }
I suggest
  270     public int codePointBefore(int index) {
  271         if ((--index < 0) || (index >= count)) {
  272             throw new StringIndexOutOfBoundsException(index);
  273         }
, because if e.g. the initial value of index is 0, then -1 reflects the out-of-bound condition,
but not the initial 0 to report in the StringIndexOutOfBoundsException.
(Hopefully the following redundant i < 0 bounds check from value[i] becomes elimited by JIT.)

Additional suggestions: 231 * @exception _String_IndexOutOfBoundsException ... 235 public int codePointAt(int index) {

259 * @exception _String_IndexOutOfBoundsException ... 263 public int codePointBefore(int index) {

For what it's worth to throw the more verbose StringIndexOutOfBoundsException, if it's not mentioned in the spec?

Additional nit: In line 231 there is an extra space before and behind IndexOutOfBoundsException (the behind one I would like to see everywhere), but in most cases of @param and @exception, the 2nd space is missing. Anyway @throws would be better than @exception

-Ulf



More information about the core-libs-dev mailing list