Fixes #21997. (cherry picked from commit f0f65087) (cherry picked from commit b4c57e1b) (cherry picked from commit a69c2401)