Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!xlned.com!feeder7.xlned.com!multikabel.net!newsfeed10.multikabel.net!post40.multikabel.net!cache100.multikabel.net!not-for-mail From: "Skybuck Flying" Newsgroups: alt.comp.lang.borland-delphi,comp.lang.c,comp.lang.java.programmer References: <29308868.1994.1337265697084.JavaMail.geo-discussion-forums@pbcuc6> In-Reply-To: <29308868.1994.1337265697084.JavaMail.geo-discussion-forums@pbcuc6> Subject: Re: Oracle/Google demonstrate human beings cannot write 10 lines of code without making a mistake ;) Date: Thu, 17 May 2012 17:26:21 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3538.513 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3538.513 Message-ID: X-Complaints-To: abuse@ziggo.nl Organization: Ziggo Lines: 106 NNTP-Posting-Host: 84.25.172.195 (84.25.172.195) NNTP-Posting-Date: Thu, 17 May 2012 17:37:37 +0200 X-Trace: e69c44fb51b41f1bc096611300 Xref: csiph.com comp.lang.c:20907 comp.lang.java.programmer:14578 "Fred K" wrote in message news:29308868.1994.1337265697084.JavaMail.geo-discussion-forums@pbcuc6... On Thursday, May 17, 2012 6:09:23 AM UTC-7, Skybuck Flying wrote: > Hello, > > My hypothesis that a human being cannot write 10 lines of code without > making a mistake has been confirmed by either oracle or google or both > depending on what you believe ;) > > The lawsuit apperently mentions these 9 lines of code: > > " > private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) { > if (fromIndex > toIndex) > throw new IllegalArgumentException("fromIndex(" + fromIndex + > ") > toIndex(" + toIndex+")"); " This is not C. " It's a curly brace language which the same kind of stupid c programming see below. > if (fromIndex < 0) > throw new ArrayIndexOutOfBoundsException(fromIndex); > if (toIndex > arrayLen) > throw new ArrayIndexOutOfBoundsException(toIndex); > } > " > > There is at least 1 major bug in it: > > toIndex could equal arrayLen which would still be out of bounds assuming > zero-index-based arrays. > > So for example if the array length is 100, then toIndex is valid for range > 0 > to 99. > > And therefore the exception should be raised for equalness to arrayLen as > well. > > So the correct code should probably have been ">=" instead of just ">". > > Except if some special outside code assumes that it's ok... I don't know > where this routine is being used... but by itself it would be flawed. > > Also fromIndex could also still go out of range past arrayLen this is also > not checked. > " Actually it is checked by the combined actions of the first and third "if" statements. " 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 as well, so it's obvious this code assumes that copieing from low to high is the only possibility. A strange assumption to make, making this code much less usuable and much less flexible in the case it needs to be adjusted to accommodate for this new functionality as will often be the case with software and changing requirements. Furthermore it seems to be an "optimization". Instead of simple using 4 branches, the code tries to do it with 3. Furthermore a dependency is added on the correctness of another branch. Since the 3 branch is incorrect the first one is now incorrect as well leading to two different possible bugs instead of just one. bug1: toIndex can now be out of bounds. bug2: fromIndex can now be out of bounds as well. Example: 100 100 This code is a nice example oh how not to program. Apperently only a skilled coder/debugger like me seems to be able to spot the fallacies in this way too debug-complex code. Lesson to be learned from this code: Do not introduce dependencies like this. > So this code seems highly buggy and does somewhat prove that it was copied > ?! > > It's a bit unlikely that two programmers make the exact same dumb mistake > ! > ;) > > So the funny part is, the bugs in it kinda prove that it was copied ! ;) > > Mimimimimimimmimimi :) Bye, Skybuck.