Forward port of issue #20716 to 2.3.x.