fixed index outside bounds of the array when 0 productions left

closes #4137