diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala index 1fa1142f00113..40a5a9e750daa 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -740,9 +740,13 @@ private[spark] object Utils extends Logging { * always return a single directory. */ def getLocalDir(conf: SparkConf): String = { - getOrCreateLocalRootDirs(conf).headOption.getOrElse { - val dirPaths = getConfiguredLocalDirs(conf) - throw new IOException(s"Failed to get a temp directory under [${dirPaths.mkString(",")}].") + val localRootDirs = getOrCreateLocalRootDirs(conf) + if (localRootDirs.nonEmpty) { + localRootDirs(0) + } else { + val configuredLocalDirs = getConfiguredLocalDirs(conf) + throw new IOException( + s"Failed to get a temp directory under [${configuredLocalDirs.mkString(",")}].") } }