Fix potential NPE and set body instead of lazy.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5ff0eb17 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5ff0eb17 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5ff0eb17 Branch: refs/heads/master Commit: 5ff0eb17a6194dbc898e9190a8f9c0cc317771be Parents: 7253ae9 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Jan 8 15:48:44 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jan 8 17:38:32 2016 +0100 ---------------------------------------------------------------------- .../apache/camel/component/irc/IrcMessage.java | 4 ++++ .../apache/camel/component/irc/IrcProducer.java | 23 ++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5ff0eb17/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java ---------------------------------------------------------------------- diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java index 48a8e6b..be4bc8a 100644 --- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java +++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java @@ -39,6 +39,7 @@ public class IrcMessage extends DefaultMessage { this.messageType = messageType; this.user = user; this.message = message; + setBody(message); } public IrcMessage(String messageType, String target, IRCUser user, String message) { @@ -46,6 +47,7 @@ public class IrcMessage extends DefaultMessage { this.target = target; this.user = user; this.message = message; + setBody(message); } public IrcMessage(String messageType, String target, IRCUser user, String whoWasKickedNick, String message) { @@ -54,6 +56,7 @@ public class IrcMessage extends DefaultMessage { this.user = user; this.whoWasKickedNick = whoWasKickedNick; this.message = message; + setBody(message); } public IrcMessage(String messageType, String target, IRCUser user) { @@ -67,6 +70,7 @@ public class IrcMessage extends DefaultMessage { this.num = num; this.value = value; this.message = message; + setBody(message); } public String getMessageType() { http://git-wip-us.apache.org/repos/asf/camel/blob/5ff0eb17/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java index 409b376..a129be9 100644 --- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java +++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java @@ -50,16 +50,18 @@ public class IrcProducer extends DefaultProducer { throw new RuntimeCamelException("Lost connection to " + connection.getHost()); } - if (isMessageACommand(msg)) { - LOG.debug("Sending command: {}", msg); - connection.send(msg); - } else if (targetChannel != null) { - LOG.debug("Sending to: {} message: {}", targetChannel, msg); - connection.doPrivmsg(targetChannel, msg); - } else { - for (IrcChannel channel : endpoint.getConfiguration().getChannels()) { - LOG.debug("Sending to: {} message: {}", channel, msg); - connection.doPrivmsg(channel.getName(), msg); + if (msg != null) { + if (isMessageACommand(msg)) { + LOG.debug("Sending command: {}", msg); + connection.send(msg); + } else if (targetChannel != null) { + LOG.debug("Sending to: {} message: {}", targetChannel, msg); + connection.doPrivmsg(targetChannel, msg); + } else { + for (IrcChannel channel : endpoint.getConfiguration().getChannels()) { + LOG.debug("Sending to: {} message: {}", channel, msg); + connection.doPrivmsg(channel.getName(), msg); + } } } } @@ -72,7 +74,6 @@ public class IrcProducer extends DefaultProducer { endpoint.joinChannels(); } - @Override protected void doStop() throws Exception { if (connection != null) {