Integrate patch for bug #1016847 into this branch