Fixed null pointer exception in case of IOException before uploading file to http host

This commit is contained in:
steckbrief 2016-04-16 21:37:19 +02:00
parent aeda55ba7c
commit c854f659db

View file

@ -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);