Forward port of issue #46666 to 4.0.x.
Forward port of issue #46666 to 4.0.x.