From 57d7870f7a170f9b7ae772b3ccc107554cbf6269 Mon Sep 17 00:00:00 2001 From: Kirill Merkushev Date: Mon, 21 Dec 2015 00:58:57 +0300 Subject: [PATCH] [FIXES JENKINS-32132] Check status message is null (in case of wrong deserialization) --- .../java/com/cloudbees/jenkins/GitHubCommitNotifier.java | 7 +++++-- .../cloudbees/jenkins/GitHubSetCommitStatusBuilder.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/GitHubCommitNotifier.java b/src/main/java/com/cloudbees/jenkins/GitHubCommitNotifier.java index 4900bc637..bb8cb7cf2 100644 --- a/src/main/java/com/cloudbees/jenkins/GitHubCommitNotifier.java +++ b/src/main/java/com/cloudbees/jenkins/GitHubCommitNotifier.java @@ -28,6 +28,7 @@ import static com.cloudbees.jenkins.Messages.GitHubCommitNotifier_DisplayName; import static com.cloudbees.jenkins.Messages.GitHubCommitNotifier_SettingCommitStatus; import static com.coravy.hudson.plugins.github.GithubProjectProperty.displayNameFor; +import static com.google.common.base.Objects.firstNonNull; import static hudson.model.Result.FAILURE; import static hudson.model.Result.SUCCESS; import static hudson.model.Result.UNSTABLE; @@ -41,8 +42,9 @@ * @author Nicolas De Loof */ public class GitHubCommitNotifier extends Notifier { + private static final ExpandableMessage DEFAULT_MESSAGE = new ExpandableMessage(""); - private ExpandableMessage statusMessage = new ExpandableMessage(""); + private ExpandableMessage statusMessage = DEFAULT_MESSAGE; private final String resultOnFailure; private static final Result[] SUPPORTED_RESULTS = {FAILURE, UNSTABLE, SUCCESS}; @@ -124,7 +126,8 @@ private void updateCommitStatus(@Nonnull AbstractBuild build, final String sha1 = ObjectId.toString(BuildDataHelper.getCommitSHA1(build)); StatusResult status = statusFrom(build); - String message = defaultIfEmpty(statusMessage.expandAll(build, listener), status.getMsg()); + String message = defaultIfEmpty(firstNonNull(statusMessage, DEFAULT_MESSAGE) + .expandAll(build, listener), status.getMsg()); String contextName = displayNameFor(build.getProject()); for (GitHubRepositoryName name : GitHubRepositoryNameContributor.parseAssociatedNames(build.getProject())) { diff --git a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java index 54245da62..0c151d05a 100644 --- a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java +++ b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java @@ -19,11 +19,14 @@ import static com.cloudbees.jenkins.Messages.GitHubCommitNotifier_SettingCommitStatus; import static com.coravy.hudson.plugins.github.GithubProjectProperty.displayNameFor; +import static com.google.common.base.Objects.firstNonNull; import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; @Extension public class GitHubSetCommitStatusBuilder extends Builder { - private ExpandableMessage statusMessage = new ExpandableMessage(""); + private static final ExpandableMessage DEFAULT_MESSAGE = new ExpandableMessage(""); + + private ExpandableMessage statusMessage = DEFAULT_MESSAGE; @DataBoundConstructor public GitHubSetCommitStatusBuilder() { @@ -50,7 +53,7 @@ public boolean perform(AbstractBuild build, BuildListener listener) throws InterruptedException, IOException { final String sha1 = ObjectId.toString(BuildDataHelper.getCommitSHA1(build)); String message = defaultIfEmpty( - statusMessage.expandAll(build, listener), + firstNonNull(statusMessage, DEFAULT_MESSAGE).expandAll(build, listener), Messages.CommitNotifier_Pending(build.getDisplayName()) ); String contextName = displayNameFor(build.getProject());