Fix a potential ArrayIndexOutOfBoundException