fix crash when there is no cache when DeleteCacheService runs

java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File; or its super classes (declaration of 'java.io.File' appears in /system/framework/core-oj.jar)
at org.apache.commons.io.FileUtils.isSymlink(FileUtils.java:3107)
at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1616)
at org.fdroid.fdroid.DeleteCacheService.onHandleWork(DeleteCacheService.java:30)
at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:391)
at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
This commit is contained in:
Hans-Christoph Steiner 2019-04-09 14:37:04 +02:00
parent 593ce5284c
commit 272a0e3f27

View File

@ -27,7 +27,10 @@ public class DeleteCacheService extends JobIntentService {
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
Log.w(TAG, "Deleting all cached contents!");
try {
FileUtils.deleteDirectory(getCacheDir());
File cacheDir = getCacheDir();
if (cacheDir != null) {
FileUtils.deleteDirectory(cacheDir);
}
for (File dir : ContextCompat.getExternalCacheDirs(this)) {
FileUtils.deleteDirectory(dir);
}