I have been trying to figure out why the code keeps giving me an arrayIndexOutOfBoundsException over and over. Out of a desperate attempt I reversed the 2 Boolean conditions in my while loop and the program worked fine. The reason this really confuses me is because the two conditions are separated by an AND clause which should be commutative. 

Here is the while statement that is in question:

```
while(compareIndex>=0 && key<data[compareIndex])//works
while(key<data[compareIndex] && compareIndex>=0) //Crashes

```

And for some context here is the rest of the method body:

```
public static void insertionSort(int[] data){
    for(int i = 0; i<data.length; i++){
        int key = data[i];
        int compareIndex = i-1;
        while(key<data[compareIndex] && compareIndex>=0){
            data[compareIndex+1] = data[compareIndex];
            compareIndex--;
        }
        data[compareIndex+1] = key;
    }

}

```