backport pull #1015 to 1.4 branch