Forward port of issue #20976 to 2.2.7.