Don't forget that System.out.println() can be your best friend. When you think "There is NO WAY the index can be out of bounds", print out what the index IS on each iteration, and you'll quickly see that your index got to '4'.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors