Bug fix: SPARK-789

https://spark-project.atlassian.net/browse/SPARK-789