A cleaner implementation of GROOVY-6589 that only gets involved when there is a duplicate.