[SPARK-2075][Core] backport for branch-1.2

backport #3740 for branch-1.2