Path: csiph.com!usenet.pasdenom.info!goblin3!goblin.stu.neva.ru!newsfeed3.funet.fi!newsfeeds.funet.fi!feeder2.news.elisa.fi!uutiset.elisa.fi!7564ea0f!not-for-mail Newsgroups: alt.comp.lang.borland-delphi,comp.lang.c,comp.lang.java.programmer From: Heikki Kallasjoki Subject: Re: Oracle/Google demonstrate human beings cannot write 10 lines of code without making a mistake ;) References: <29308868.1994.1337265697084.JavaMail.geo-discussion-forums@pbcuc6> Organization: nonexistent Followup-To: comp.lang.java.programmer User-Agent: slrn/pre1.0.0-18 (Linux) Message-ID: Lines: 28 Date: Thu, 17 May 2012 16:19:00 GMT NNTP-Posting-Host: 91.156.75.88 X-Complaints-To: newsmaster@saunalahti.com X-Trace: uutiset.elisa.fi 1337271540 91.156.75.88 (Thu, 17 May 2012 19:19:00 EEST) NNTP-Posting-Date: Thu, 17 May 2012 19:19:00 EEST Xref: csiph.com comp.lang.c:20909 comp.lang.java.programmer:14582 On 2012-05-17, Skybuck Flying wrote: >> private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) { >> if (fromIndex > toIndex) >> throw new IllegalArgumentException("fromIndex(" + fromIndex + >> ") > toIndex(" + toIndex+")"); >> if (fromIndex < 0) >> throw new ArrayIndexOutOfBoundsException(fromIndex); >> if (toIndex > arrayLen) >> throw new ArrayIndexOutOfBoundsException(toIndex); >> } > A very perverse way. The mission is to check if indexes are outside the > array "out of bounds". > > Furthermore it makes no sense, copieing from high to low should be possible Who said anything about copying? I believe it is checking whether the range fromIndex, fromIndex+1, ..., toIndex-1 -- i.e., a range given as the first index and one past the last index, not an uncommon practice -- is within the array, in which case it has no bugs. (toIndex may legally equal the length of the array when the range extends to the last element, and requiring the range to be specified "the right way around" is not especially perverse.) -- Heikki Kallasjoki