Merge #6498 fix from 3.1.