Forward port of issue #21213 to 2.3.0.