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() --- juick-www/src/main/java/com/juick/www/controllers/NewMessage.java | 3 ++- .../pebble/extension/filters/FormatMessageFilter.java | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'juick-www/src') diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index 9e022557..ea81b5e0 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -254,7 +254,8 @@ public class NewMessage { com.juick.Message jmsg = messagesService.getReply(mid, ridnew); xmsg.addExtension(jmsg); - String quote = reply != null ? reply.getText() : msg.getText(); + String quote = reply != null ? StringUtils.defaultString(reply.getText()) + : StringUtils.defaultString(msg.getText()); if (quote.length() >= 50) { quote = quote.substring(0, 47) + "..."; } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java index d127daa9..b492f121 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java @@ -21,6 +21,7 @@ import com.juick.Message; import com.juick.util.MessageUtils; import com.mitchellbosecke.pebble.extension.Filter; import com.mitchellbosecke.pebble.extension.escaper.SafeString; +import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; @@ -34,8 +35,8 @@ public class FormatMessageFilter implements Filter { if (input instanceof Message) { Message msg = (Message) input; boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code")); - String formattedMessage = isCode ? MessageUtils.formatMessageCode(msg.getText()) - : MessageUtils.formatMessage(msg.getText()); + String formattedMessage = isCode ? MessageUtils.formatMessageCode(StringUtils.defaultString(msg.getText())) + : MessageUtils.formatMessage(StringUtils.defaultString(msg.getText())); return new SafeString(formattedMessage); } throw new IllegalArgumentException("invalid input"); -- cgit v1.2.3