Forward port of issue #19838 to 2.2.5.