Forward port of issue #21318 to 2.3.0.