Forward port of issue #19944 to 2.2.5.