From cccd15e4dc1ba769727fdfeb3359c2307f3e8ac6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 18 Sep 2016 22:15:02 +0200 Subject: don't simply ignore null in message body but try to avoid it --- src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java | 6 +++++- src/main/java/de/pixart/messenger/entities/Message.java | 6 ++++-- src/main/java/de/pixart/messenger/utils/UIHelper.java | 4 +--- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java b/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java index 02c094b71..b3f2e64da 100644 --- a/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java +++ b/src/main/java/de/pixart/messenger/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/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 20a7ea002..26847b37a 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/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,7 +266,9 @@ public class Message extends AbstractEntity { } public void setBody(String body) { - this.body = body; + if (body == null) { + throw new Error("You should not set the message body to null"); + } } public long getTimeSent() { diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index 7e2d46018..fbd41fa0a 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -180,9 +180,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)) { -- cgit v1.2.3