From 62df283157ff32dded77e833fbd0f4e3007acbbe Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 17 Jan 2018 13:33:50 +0300 Subject: prevent nulls with StringUtils.defaultString() --- .../src/main/java/com/juick/formatters/PlainTextFormatter.java | 8 ++++---- juick-core/src/main/java/com/juick/util/MessageUtils.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'juick-core/src/main/java/com') diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java index bd4cfedb..459384fb 100644 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java @@ -37,7 +37,7 @@ public class PlainTextFormatter { String title = isReply ? "Reply by @" : "@"; String subtitle = isReply ? jmsg.getReplyQuote() : jmsg.getTagsString(); sb.append(title).append(jmsg.getUser().getName()).append(":\n") - .append(subtitle).append("\n").append(jmsg.getText()).append("\n"); + .append(subtitle).append("\n").append(StringUtils.defaultString(jmsg.getText())).append("\n"); if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { // FIXME: attachment does not serialized to xml if (jmsg.getAttachment() == null) { @@ -60,8 +60,8 @@ public class PlainTextFormatter { String timeAgo = pt.format(Date.from(m.getTimestamp())); String repliesCount = m.getReplies() == 1 ? "; 1 reply" : m.getReplies() == 0 ? "" : String.format("; %d replies", m.getReplies()); - String txt = m.getText().length() >= cropLength ? - StringUtils.substring(m.getText(), 0, cropLength) + " [...]" : m.getText(); + String txt = StringUtils.defaultString(m.getText()).length() >= cropLength ? + StringUtils.substring(StringUtils.defaultString(m.getText()), 0, cropLength) + " [...]" : m.getText(); return String.format("@%s:%s\n%s\n#%d (%s%s) http://juick.com/%d", m.getUser().getName(), m.getTagsString(), txt, m.getMid(), timeAgo, repliesCount, m.getMid()); } @@ -74,6 +74,6 @@ public class PlainTextFormatter { } public static String formatTwitterCard(Message jmsg) { - return MessageUtils.getMessageHashTags(jmsg) + jmsg.getText(); + return MessageUtils.getMessageHashTags(jmsg) + StringUtils.defaultString(jmsg.getText()); } } diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java index d032ce8e..aba718a5 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -152,7 +152,8 @@ public class MessageUtils { sb.append(title).append(jmsg.getUser().getName()).append(":
") .append(subtitle).append("
") - .append(isCode ? formatMessageCode(jmsg.getText()) : formatMessage(jmsg.getText())).append("
"); + .append(isCode ? formatMessageCode(StringUtils.defaultString(jmsg.getText())) + : formatMessage(StringUtils.defaultString(jmsg.getText()))).append("
"); if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { // FIXME: attachment does not serialized to xml if (jmsg.getAttachment() == null) { -- cgit v1.2.3