Skip to content
Snippets Groups Projects
Commit 27726079 authored by Evan Chan's avatar Evan Chan
Browse files

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.
parent 1e15feb5
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment