Forward port of issue #20916 to 2.3.x.