spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pwend...@apache.org
Subject [40/50] git commit: Print out more friendly error if listFiles() fails
Date Tue, 10 Sep 2013 19:32:45 GMT
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.


Project: http://git-wip-us.apache.org/repos/asf/incubator-spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spark/commit/27726079
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spark/tree/27726079
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spark/diff/27726079

Branch: refs/remotes/origin/branch-0.8
Commit: 27726079e4e6931c071de77e91f991cb1b249d02
Parents: 1e15feb
Author: Evan Chan <ev@ooyala.com>
Authored: Mon Sep 9 12:58:12 2013 -0700
Committer: Evan Chan <ev@ooyala.com>
Committed: Mon Sep 9 12:58:12 2013 -0700

----------------------------------------------------------------------
 core/src/main/scala/org/apache/spark/util/Utils.scala | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/27726079/core/src/main/scala/org/apache/spark/util/Utils.scala
----------------------------------------------------------------------
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 468800b..a95eae9 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)
       }
     }


Mime
View raw message