SI-8153 Mutation is hard, let's go shopping with an empty list

Changed the implementation of iterator to be more robust to mutation of the underlying ListBuffer.

Test added to verify the fix.