From cfb75078e0299d7569dc4a662c6842c66c646a20 Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Fri, 13 Mar 2020 22:36:45 -0400 Subject: [PATCH] [Issue #178] Check that a directory has entries before searching it. --- .../org/comixed/service/file/FileService.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/comixed-services/src/main/java/org/comixed/service/file/FileService.java b/comixed-services/src/main/java/org/comixed/service/file/FileService.java index 68508f3ce..3d8358b67 100644 --- a/comixed-services/src/main/java/org/comixed/service/file/FileService.java +++ b/comixed-services/src/main/java/org/comixed/service/file/FileService.java @@ -101,22 +101,24 @@ public List getAllComicsUnder(final String rootDirectory) throws IO private void loadFilesUnder(final List files, final File directory) throws IOException { this.logger.debug("Loading files in directory: {}", directory); - for (File file : directory.listFiles()) { - if (file.isDirectory()) { - this.loadFilesUnder(files, file); - } else { - if (ComicFileUtils.isComicFile(file)) { - final String filePath = file.getCanonicalPath(); - final long fileSize = file.length(); - - final Comic comic = this.comicRepository.findByFilename(filePath); - - if (comic != null) { - this.logger.debug("File already in the library: id={}", comic.getId()); - } else { - this.logger.debug("Adding file: {} ({} bytes)", filePath, fileSize); - - files.add(new FileDetails(filePath, fileSize)); + if (directory.listFiles() != null) { + for (File file : directory.listFiles()) { + if (file.isDirectory()) { + this.loadFilesUnder(files, file); + } else { + if (ComicFileUtils.isComicFile(file)) { + final String filePath = file.getCanonicalPath(); + final long fileSize = file.length(); + + final Comic comic = this.comicRepository.findByFilename(filePath); + + if (comic != null) { + this.logger.debug("File already in the library: id={}", comic.getId()); + } else { + this.logger.debug("Adding file: {} ({} bytes)", filePath, fileSize); + + files.add(new FileDetails(filePath, fileSize)); + } } } }