[2.7.x] NEXUS-6249: Fix and UT

Backported to Nexus 2.7.x, original PR
https://github.com/sonatype/nexus-oss/pull/341

Issue
https://issues.sonatype.org/browse/NEXUS-6249

CI
TBD