[SPARK-2678][Core] Backport PR #1801 to branch-1.0

Backport  SPARK-2678 fix in PR #1801 to branch-1.0

Author: Cheng Lian <lian.cs.zju@gmail.com>

Closes #1831 from liancheng/spark-2678-for-1.0 and squashes the following commits:

cc59929 [Cheng Lian] Backported SPARK-2678 fix