From 3bb095bef8cbbf44d157da6267768e24a14f2a30 Mon Sep 17 00:00:00 2001 From: Nicolas VINOT Date: Mon, 5 Sep 2011 10:41:12 +0200 Subject: [PATCH] Fix NPE if a participant hasn't message in an individual topic --- .../fr/imirhil/april/hebdobot/IndividualTopic.java | 4 ++++ .../java/fr/imirhil/april/hebdobot/Meeting.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/imirhil/april/hebdobot/IndividualTopic.java b/src/main/java/fr/imirhil/april/hebdobot/IndividualTopic.java index e9c5a63..1cfe701 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/IndividualTopic.java +++ b/src/main/java/fr/imirhil/april/hebdobot/IndividualTopic.java @@ -31,4 +31,8 @@ public class IndividualTopic extends Topic { public List getMessages(final String author) { return this.messages.get(author); } + + public boolean hasParticipant(final String participant) { + return this.messages.containsKey(participant); + } } diff --git a/src/main/java/fr/imirhil/april/hebdobot/Meeting.java b/src/main/java/fr/imirhil/april/hebdobot/Meeting.java index 75f01d4..8779641 100644 --- a/src/main/java/fr/imirhil/april/hebdobot/Meeting.java +++ b/src/main/java/fr/imirhil/april/hebdobot/Meeting.java @@ -56,11 +56,14 @@ public class Meeting { buffer.append(getLine( Meeting.USER_SERVICE.getRealName(participant), '-')); for (final IndividualTopic topic : this.individualTopics) { - buffer.append("\n"); - buffer.append(getTopic(topic)); - buffer.append("\n"); - for (final Message message : topic.getMessages(participant)) { - buffer.append("* " + message.getContent() + "\n"); + if (topic.hasParticipant(participant)) { + buffer.append("\n"); + buffer.append(getTopic(topic)); + buffer.append("\n"); + for (final Message message : topic + .getMessages(participant)) { + buffer.append("* " + message.getContent() + "\n"); + } } } }