Forward port of issue #21446 to 2.2.8.