Fix possible NullPointerException and ArrayIndexOutOfBoundsException.