Forward port of issue #15358 to 2.2.x.