Permalink
Browse files

Fix NullPointerException when calling _cleanup when listFiles returns…

… null.

Since this is usually caused by a permissions issue, a WARN level log event is issued to indicate the problem, and the _cleanup call returns a 500 to indicate a server-side error.

Closes #83.
  • Loading branch information...
1 parent 0544f24 commit f8cca5bf00a7db394d7c7ed90832d86b85060b7d Robert Newson committed Oct 2, 2010
Showing with 15 additions and 8 deletions.
  1. +15 −8 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
View
23 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
@@ -91,14 +91,21 @@ private void cleanup(final HttpServletRequest req,
}
}
- // Delete all indexes except the keepers.
- for (final File dir : DatabaseIndexer.uuidDir(root, db.getUuid())
- .listFiles()) {
- if (!viewKeep.contains(dir.getName())) {
- LOG.info("Cleaning old index at " + dir);
- FileUtils.deleteDirectory(dir);
- }
- }
+ // Delete all indexes except the keepers.
+ final File[] dirs = DatabaseIndexer.uuidDir(root, db.getUuid()).listFiles();
+ if (dirs == null) {
+ LOG.warn(DatabaseIndexer.uuidDir(root, db.getUuid())
+ + " is not a directory or could not be read.");
+ ServletUtils.sendJSONError(req, resp, 500, "index_dir_perms");
+ return;
+ } else {
+ for (final File dir : dirs) {
+ if (!viewKeep.contains(dir.getName())) {
+ LOG.info("Cleaning old index at " + dir);
+ FileUtils.deleteDirectory(dir);
+ }
+ }
+ }
}
// Delete all directories except the keepers.

0 comments on commit f8cca5b

Please sign in to comment.