Issue 787 backport 4.0.x