From badc97e2806755e9811f1c0bc3d803c0bddb7be7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 18 Sep 2016 22:15:02 +0200 Subject: [PATCH] don't simply ignore null in message body but try to avoid it --- .../eu/siacs/conversations/crypto/PgpDecryptionService.java | 6 +++++- src/main/java/eu/siacs/conversations/entities/Message.java | 5 ++++- src/main/java/eu/siacs/conversations/utils/UIHelper.java | 4 +--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java index 537687148..63f846c57 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java @@ -115,7 +115,11 @@ public class PgpDecryptionService { case OpenPgpApi.RESULT_CODE_SUCCESS: try { os.flush(); - message.setBody(os.toString()); + final String body = os.toString(); + if (body == null) { + throw new IOException("body was null"); + } + message.setBody(body); message.setEncryption(Message.ENCRYPTION_DECRYPTED); final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager(); if (message.trusted() diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 1b38d3498..4ff082756 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -124,7 +124,7 @@ public class Message extends AbstractEntity { this.conversationUuid = conversationUUid; this.counterpart = counterpart; this.trueCounterpart = trueCounterpart; - this.body = body; + this.body = body == null ? "" : body; this.timeSent = timeSent; this.encryption = encryption; this.status = status; @@ -266,6 +266,9 @@ public class Message extends AbstractEntity { } public void setBody(String body) { + if (body == null) { + throw new Error("You should not set the message body to null"); + } this.body = body; } diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index bf997bc13..faf4b3a5c 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -181,9 +181,7 @@ public class UIHelper { } } else { String body = message.getBody(); - if (body == null) { - body = ""; - } else if (body.length() > 256) { + if (body.length() > 256) { body = body.substring(0,256); } if (body.startsWith(Message.ME_COMMAND)) {