Forward port of issue #20037 to 2.3.x.