Fixes #21997. (cherry picked from commit f0f65087) (cherry picked from commit b4c57e1b)
mentioned in commit 4c75f81c