From 71150a36d288f4a182a1c4f2a26fbe76cf8d2a73 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Mon, 11 Jul 2016 06:34:16 +0200 Subject: [PATCH] Don't die with NPEs if a MediaFileManager tries to download an Empty media thing. --- .../mediafilemanager/DocumentFileManager.java | 10 ++++++++-- .../mediafilemanager/PhotoFileManager.java | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.java b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.java index 1a57640..29700ab 100644 --- a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.java @@ -68,10 +68,14 @@ public class DocumentFileManager extends AbstractMediaFileManager { return sticker!=null; } - public int getSize() { return doc.getSize(); } + public int getSize() { + if (doc != null) return doc.getSize(); + return 0; + } public String getExtension() { if (extension != null) return extension; + if (doc == null) return "empty"; String ext = null; String original_filename = null; for(TLAbsDocumentAttribute attr : doc.getAttributes()) { @@ -92,7 +96,9 @@ public class DocumentFileManager extends AbstractMediaFileManager { } public void download() throws RpcErrorException, IOException { - DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), doc.getDcId(), doc.getId(), doc.getAccessHash()); + if (doc!=null) { + DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), doc.getDcId(), doc.getId(), doc.getAccessHash()); + } } public String getLetter() { return "d"; } diff --git a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.java b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.java index 1574b30..b0110ad 100644 --- a/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.java @@ -70,12 +70,14 @@ public class PhotoFileManager extends AbstractMediaFileManager { } public int getSize() { - return size.getSize(); + if (size!=null) return size.getSize(); + return 0; } public String getExtension() { return "jpg"; } public void download() throws RpcErrorException, IOException { + if (isEmpty) return; TLFileLocation loc = (TLFileLocation) size.getLocation(); DownloadManager.downloadFile(client, getTargetPathAndFilename(), getSize(), loc.getVolumeId(), loc.getLocalId(), loc.getSecret()); }