I believe the bug is on this line. You've already consumed the parameter at index 0 up on line 70, but then you do list.get(index++). I believe this ought to be list ...