Port of Pull Request #7022 to master branch