From 4d5dc70cb358df8732c6aa5f3491fe39c6755452 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 27 Jun 2019 16:10:41 +0200 Subject: catch NPE --- .../messenger/services/XmppConnectionService.java | 37 +++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index b9945de0a..09739530d 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -767,23 +767,30 @@ public class XmppConnectionService extends Service { private void deleteWebpreviewCache() { long start = SystemClock.elapsedRealtime(); - final String path = getApplicationContext().getCacheDir() + "/" + RICH_LINK_METADATA; - final Calendar time = Calendar.getInstance(); - time.add(Calendar.DAY_OF_YEAR, -7); - final File directory = new File(path); - final File[] files = directory.listFiles(); - if (files == null) { - return; - } - int count = 0; - for (File file : files) { - Date lastModified = new Date(file.lastModified()); - if (lastModified.before(time.getTime())) { - file.delete(); - count++; + try { + final String path = getApplicationContext().getCacheDir() + "/" + RICH_LINK_METADATA; + final Calendar time = Calendar.getInstance(); + time.add(Calendar.DAY_OF_YEAR, -7); + final File directory = new File(path); + if (!directory.exists()) { + return; } + final File[] files = directory.listFiles(); + if (files == null) { + return; + } + int count = 0; + for (File file : files) { + Date lastModified = new Date(file.lastModified()); + if (lastModified.before(time.getTime())) { + file.delete(); + count++; + } + } + Log.d(Config.LOGTAG, "Deleted " + count + " expired webpreview cache files in " + (SystemClock.elapsedRealtime() - start) + "ms"); + } catch (Exception e) { + Log.d(Config.LOGTAG, "Deleted no expired webpreview cache files because of " + e + " in " + (SystemClock.elapsedRealtime() - start) + "ms"); } - Log.d(Config.LOGTAG, "Deleted " + count + " expired webpreview cache files in " + (SystemClock.elapsedRealtime() - start) + "ms"); } private boolean processAccountState(Account account, boolean interactive, boolean isUiAction, boolean isAccountPushed, HashSet pingCandidates) { -- cgit v1.2.3