From 0c6b4a7ef65adc2db8aa8025b8daf97c7c850c9f Mon Sep 17 00:00:00 2001 From: Yestin Sun Date: Fri, 18 Mar 2016 17:33:34 -0700 Subject: [PATCH] Fix #62 by excluding empty affected files collection Jenkins Repo plugin adds an "empty" change log when there is a new project added or removed, e.g.: path: local/path serverPath: server/path revision: null authorName: null authorEmail: null authorDate: null committerName: null committerEmail: null committerDate: null commitText: This project was added from the manifest. modifiedFiles: null When Slack plugin tries to add the "null" affected files, it gets a NullPointerException error. Fix the error by not adding any empty affected files collection. --- src/main/java/jenkins/plugins/slack/ActiveNotifier.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/jenkins/plugins/slack/ActiveNotifier.java b/src/main/java/jenkins/plugins/slack/ActiveNotifier.java index 03ab2ecd..da31bbaf 100755 --- a/src/main/java/jenkins/plugins/slack/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/slack/ActiveNotifier.java @@ -16,6 +16,7 @@ import hudson.tasks.test.AbstractTestResultAction; import hudson.triggers.SCMTrigger; import hudson.util.LogTaskListener; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import java.io.IOException; @@ -128,7 +129,9 @@ String getChanges(AbstractBuild r, boolean includeCustomMessage) { Entry entry = (Entry) o; logger.info("Entry " + o); entries.add(entry); - files.addAll(entry.getAffectedFiles()); + if (CollectionUtils.isNotEmpty(entry.getAffectedFiles())) { + files.addAll(entry.getAffectedFiles()); + } } if (entries.isEmpty()) { logger.info("Empty change...");