Forward port of issue #21716 to 2.2.x.