Repository: cassandra
Updated Branches:
  refs/heads/trunk a88c7e10f -> 90ade6b45


Avoid NPE when listing saved caches directory

Patch by marcuse; reviewed by yukim for CASSANDRA-7632


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/1a0aaf04
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/1a0aaf04
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/1a0aaf04

Branch: refs/heads/trunk
Commit: 1a0aaf04986155eae45b2685d234b928866b681c
Parents: 892bf55
Author: Marcus Eriksson <marc...@apache.org>
Authored: Thu Jul 31 07:53:33 2014 +0200
Committer: Marcus Eriksson <marc...@apache.org>
Committed: Thu Jul 31 07:53:33 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../apache/cassandra/cache/AutoSavingCache.java | 23 ++++++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1a0aaf04/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a6fc837..1fcb556 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -22,6 +22,7 @@
  * Fix error when doing reversed queries with static columns (CASSANDRA-7490)
  * Backport CASSANDRA-6747 (CASSANDRA-7560)
  * Track max/min timestamps for range tombstones (CASSANDRA-7647)
+ * Fix NPE when listing saved caches dir (CASSANDRA-7632)
 Merged from 1.2:
  * Set correct stream ID on responses when non-Exception Throwables
    are thrown while handling native protocol messages (CASSANDRA-7470)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1a0aaf04/src/java/org/apache/cassandra/cache/AutoSavingCache.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cache/AutoSavingCache.java 
b/src/java/org/apache/cassandra/cache/AutoSavingCache.java
index 6554eb3..64234e2 100644
--- a/src/java/org/apache/cassandra/cache/AutoSavingCache.java
+++ b/src/java/org/apache/cassandra/cache/AutoSavingCache.java
@@ -261,19 +261,24 @@ public class AutoSavingCache<K extends CacheKey, V> 
extends InstrumentingCache<K
         {
             File savedCachesDir = new 
File(DatabaseDescriptor.getSavedCachesLocation());
             assert savedCachesDir.exists() && savedCachesDir.isDirectory();
-
-            for (File file : savedCachesDir.listFiles())
+            File[] files = savedCachesDir.listFiles();
+            if (files != null)
             {
-                if (!file.isFile())
-                    continue; // someone's been messing with our directory.  
naughty!
-
-                if (file.getName().endsWith(cacheType.toString())
-                    || file.getName().endsWith(String.format("%s-%s.db", 
cacheType.toString(), CURRENT_VERSION)))
+                for (File file : files)
                 {
-                    if (!file.delete())
-                        logger.warn("Failed to delete {}", 
file.getAbsolutePath());
+                    if (!file.isFile())
+                        continue; // someone's been messing with our 
directory.  naughty!
+
+                    if (file.getName().endsWith(cacheType.toString())
+                            || 
file.getName().endsWith(String.format("%s-%s.db", cacheType.toString(), 
CURRENT_VERSION)))
+                    {
+                        if (!file.delete())
+                            logger.warn("Failed to delete {}", 
file.getAbsolutePath());
+                    }
                 }
             }
+            else
+                logger.warn("Could not list files in {}", savedCachesDir);
         }
     }
 

Reply via email to