This loop is strange.
I ran this in Java, it gives an Index out of bounds exception. I can't find an int l declaration anywhere in the source code and i can't figure out what it is and found out that it is legal for it to be declared this way.
But the deal here is, i don't understand what this piece of code is doing. For any size of resultSIList, it gives an ArrayIndexOutOfBoundsException.
for (int i = offset, l = Math.min(i + maxItemsInOnePage, totalSIs); i < l; i++){
resultSIList.get(i);
}
EDIT: Thanks all.
Here is a runnable code i am using to try to understand this entire loop. Yes it is a horrible piece of junk.
public class IndexOutOfBoundsTest {
public static void main(String args[]){
int offset = 50;
int maxItemsInOnePage = 50;
int totalSIs = 50;
final int buildThis = 15;
List resultSIList = new ArrayList();
// build list
for(int zz = 0; zz < buildThis; zz ++){
resultSIList.add("Hi " + zz);
}
try{
for (int i = offset,
d = Math.min(i + maxItemsInOnePage, totalSIs);
i < d; i++){
System.out.println(resultSIList.get(i));
}
}catch(Exception e){
e.printStackTrace();
}
}
}
offset?ifromoffsettoMath.min(offset + maxItemsInOnePage, totalSIs)-1. (The initialization is horribly written, but that's what it does as far as I understand.) But how could anyone here know what those variables are? What'sresultSIList, etc.? You must post the whole relevant code, otherwise no one can help you.