Forward port of issue #19910 to 2.2.x.