aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-17 13:33:50 +0300
committerGravatar Vitaly Takmazov2018-01-17 13:33:50 +0300
commit62df283157ff32dded77e833fbd0f4e3007acbbe (patch)
tree8e213bcc99b4f1679ba0d03ce6eef0cf8421156c /juick-core/src/main/java
parent34e33eb5202570e8343382df7ca6a2e87385a611 (diff)
prevent nulls with StringUtils.defaultString()
Diffstat (limited to 'juick-core/src/main/java')
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java8
-rw-r--r--juick-core/src/main/java/com/juick/util/MessageUtils.java3
2 files changed, 6 insertions, 5 deletions
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(":</b></br/>")
.append(subtitle).append("<br/>")
- .append(isCode ? formatMessageCode(jmsg.getText()) : formatMessage(jmsg.getText())).append("<br />");
+ .append(isCode ? formatMessageCode(StringUtils.defaultString(jmsg.getText()))
+ : formatMessage(StringUtils.defaultString(jmsg.getText()))).append("<br />");
if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) {
// FIXME: attachment does not serialized to xml
if (jmsg.getAttachment() == null) {