After reading about the Oracle v. Google trial I looked up the famous 9 lines of code that Google allegedly stole from Oracle, which implement the rangeCheck method for arrays. Note that arrays and range checking are as common as dirt in programming languages. Any developer would be hard pressed to write a rangeCheck method that is entirely dissimilar from those 9 lines. However, in this case the Android version of this method from Google is identical to the Java implementation from Oracle. Although Google tried very very hard to make sure there are no literal copies from the Java implementation – they did a cleanroom implementation of Android – one developer somehow slipped in the rangeCheck implementation “as a temporary measure”.

Now where did I hear this before? Every company tries to control its developers’ actions, but does management really know what goes into the software? The combination of internet, open source code bases and search engines tempt every developer to search for a piece of code that probably exists already and does what he or she has to implement. If a new version of this code is then implemented with the same functionality, there’s no harm done. However, it’s not functionality that the developer is after, but a ready-made, cut-and-tried, consumable piece of code. Many developers mistakenly think open source code is fair game because it’s open and free. And most of the time, they do it “as a temporary measure”. Another way this happens is when a developer moves companies and copies part of his previous employer’s code into the new employer’s software. Again, “as a temporary measure”. This is just something that developers do. When I warn my students about this I see eyes glaze over at best.

To make matters worse in the Oracle v. Google case, this same developer, while employed by Google, also contributed these 9 lines as part of a much faster implementation for sorting arrays to OpenJDK, an open implementation of JavaSE, then controlled by Sun (now Oracle).

Anyway, Google seems to be winning the argument on this one and Oracle will probably not get the pots of money it was expecting. But we’re probably not all as smart as Google…

Background

Oracle is suing Google because Android allegedly infringes Oracle’s Java patents and copyright. Oracle acquired Sun Microsystems early 2010 and thus Java. Apparently Oracle experts estimated that Google owes Oracle between $1.4 billion and $6 billion in damages if liable, but these amounts are still under debate.

Patent claims

Google has managed to eliminate most of Oracle’s patent claims, mainly by having the patents reexamined for novelty. Simply put, this means that Google has come up with a huge amount of references that date before the patents were first filed and show that what was patented already existed. However, the phase of the trial covering the patents is being held right now, so no definite outcome yet.

Copyright claims

Furthermore, the copyright claims are also being dismanteled steadily but surely, although admittedly the main issue is as of yet undecided: the judge still has to declare whether the structure, sequence and organization of 37 API’s that Java and Android have in common is copyrightable. It’s interesting to note that the EU Court of Justice just ruled that API’s are not copyrightable. In addition to this issue, there is some literal copying of code and comments from Java in some Android files. Although the jury couldn’t reach a unanimous decision on all questions, they did agree on the particular 9 lines that implement the rangeCheck method, as shown in the figure. Well, no surprise there, since Google admitted these lines were copied. They argue that the amount of lines copied is negligable.

The 9 lines themselves

So let’s take a closer look at how these 9 lines got there. After a couple of days in court Joshua Bloch was called as a witness by Oracle. Bloch used to work for Sun as a developer on the Java API’s. In 2004 he joined Google and in 2008 he started working on Android. However, while working for Google, he still contributed to the OpenJDK, an open implementation of the Java SE platform, controlled by Sun at the time. One of the things he contributed was a much faster implementation for sorting arrays, based on the algorithm TimSort used in Python. Both the old and new algorithm had the rangeCheck method in common, so he just copied it from the old implementation, as “a temporary measure”. And some way or other this same rangeCheck method ended up in Android.

Arrays are as common as dirt in programming languages, and range checking is inherent to collections, such as arrays, list, dictionaries. It basically checks whether a data element is within a certain range before performing operations with it. For example, you always want to check if y is different from zero before dividing x by y, or if i is between 0 and 11 before retrieving the ith element of a 10-element list. If you don’t, or more aptly, if your programming environment doesn’t, your software fails.

And here are the famous 9 lines:

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);
}
Follow

Get every new post delivered to your Inbox.