Forward port of issue #20386 to 2.2.6.