Fix potential infinite loop

The original code would yield an infinite loop if `next()` is null - the inequality comparison would yield `true` and the loop would continue forever. Maybe it doesn't matter here but it will once the surrounding code is changed or this code is copy-pasted somewhere else.