This is explained in the comment. The if statement before could potentially make the length 0.