Forward port of issue #18915 to 2.2.5.