From 27726079e4e6931c071de77e91f991cb1b249d02 Mon Sep 17 00:00:00 2001 From: Evan Chan Date: Mon, 9 Sep 2013 12:58:12 -0700 Subject: Print out more friendly error if listFiles() fails listFiles() could return null if the I/O fails, and this currently results in an ugly NPE which is hard to diagnose. --- core/src/main/scala/org/apache/spark/util/Utils.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'core/src/main') 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 468800b2bd..a95eae9c69 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -457,12 +457,18 @@ private[spark] object Utils extends Logging { def newDaemonFixedThreadPool(nThreads: Int): ThreadPoolExecutor = Executors.newFixedThreadPool(nThreads, daemonThreadFactory).asInstanceOf[ThreadPoolExecutor] + private def listFilesSafely(file: File): Seq[File] = { + val files = file.listFiles() + if (files == null) throw new IOException("Failed to list files for dir: " + file) + files + } + /** * Delete a file or directory and its contents recursively. */ def deleteRecursively(file: File) { if (file.isDirectory) { - for (child <- file.listFiles()) { + for (child <- listFilesSafely(file)) { deleteRecursively(child) } } -- cgit v1.2.3 From fdb8b0eec3e423e601de8c79658c4644717f4e05 Mon Sep 17 00:00:00 2001 From: Evan Chan Date: Mon, 9 Sep 2013 14:29:32 -0700 Subject: Style fix: put body of if within curly braces --- core/src/main/scala/org/apache/spark/util/Utils.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core/src/main') 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 a95eae9c69..a89e245322 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -459,7 +459,9 @@ private[spark] object Utils extends Logging { private def listFilesSafely(file: File): Seq[File] = { val files = file.listFiles() - if (files == null) throw new IOException("Failed to list files for dir: " + file) + if (files == null) { + throw new IOException("Failed to list files for dir: " + file) + } files } -- cgit v1.2.3