From c854f659dbf03ac92f3cb5539b4b424a993acfac Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 16 Apr 2016 21:37:19 +0200 Subject: Fixed null pointer exception in case of IOException before uploading file to http host --- .../thedevstack/conversationsplus/http/HttpUploadConnection.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java index f28dee36..6834fdd2 100644 --- a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java @@ -97,6 +97,7 @@ public class HttpUploadConnection implements Transferable { public void init(Message message, boolean delay) { this.message = message; + this.message.setHttpUploaded(true); this.account = message.getConversation().getAccount(); this.file = FileBackend.getFile(message, false); this.mime = this.file.getMimeType(); @@ -220,8 +221,12 @@ public class HttpUploadConnection implements Transferable { fail(); } } catch (IOException e) { - errorStream = connection.getErrorStream(); - Logging.e("httpupload", "http response: " + new Scanner(errorStream).useDelimiter("\\A").next() + ", exception message: " + e.getMessage()); + errorStream = (null != connection) ? connection.getErrorStream() : null; + String httpResponseMessage = null; + if (null != errorStream) { + httpResponseMessage = new Scanner(errorStream).useDelimiter("\\A").next(); + } + Logging.e("httpupload", ((null != httpResponseMessage) ? ("http response: " + httpResponseMessage + ", ") : "") + "exception message: " + e.getMessage()); fail(); } finally { StreamUtil.close(os); -- cgit v1.2.3