Forward port of issue #20507 to 2.2.7.