ref #8916 try to fix ConcurrentModificationException by using temporary set