Fix #646 for 2.5, too risky for backport.