#1795 Use ArrayList instead of HashSet (cherry-picked from 3.x branch)