From db98ee80069b8077a9c76bcbd4305c6c9a5654ab Mon Sep 17 00:00:00 2001 From: Antony Mykolaj Date: Mon, 2 May 2016 18:12:25 +0300 Subject: [PATCH] [plugin updates] Print file names of a cache files which are failed to be deleted to log. -- Fix 'find-bugs-plugin' check warnings in 'removeAllDataFromCache()' to prepare a transition to 'find-bugs-plugin:3.0.3' --- .../file/InFileObjectPersister.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java b/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java index 05549a074..1e84b6bb5 100644 --- a/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java +++ b/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java @@ -138,21 +138,31 @@ public boolean removeDataFromCache(Object cacheKey) { @Override public void removeAllDataFromCache() { - File cacheFolder = getCacheFolder(); - File[] cacheFileList = cacheFolder.listFiles(new FileFilter() { + File folder = getCacheFolder(); + if (folder == null) { + Ln.d("Skip 'removeAllDataFromCache' operation. Cache folder is 'null', so there's" + + " nothing to remove."); + return; + } + File[] cacheFileList = folder.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.getName().startsWith(getCachePrefix()); } }); - - boolean allDeleted = true; - for (File cacheFile : cacheFileList) { - allDeleted = cacheFile.delete() && allDeleted; + if (cacheFileList == null) { + Ln.d("Cache is already clear."); + return; } - if (allDeleted || cacheFileList.length == 0) { - Ln.d("Some file could not be deleted from cache."); + for (File cacheFile : cacheFileList) { + // Calm down the 'find-bugs-plugin' which complains about a possible NPE here + if (cacheFile == null) { + continue; + } + if (!cacheFile.delete()) { + Ln.d("File '" + cacheFile.getName() + "' could not be deleted from cache."); + } } }