A cleaner implementation of GROOVY-6589 that only gets involved when there is a duplicate.
Merge remote-tracking branch 'upstream/master'