IndexOutOfBoundsException fix when validating messages