2.3.x port of pull request #7022