From 622996188ee27ee62a3c1fdadaf9fa4a6da0e2f9 Mon Sep 17 00:00:00 2001 From: Hendrik Coetzee Date: Tue, 3 May 2016 18:18:15 +0200 Subject: [PATCH 1/2] Swap equals check around to prevent NPE Swapped equals check on strings around to prevent NPE and let the code handle the missing header condition as intended. --- .../com/dabsquared/gitlabjenkins/webhook/ActionResolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java b/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java index 866b72413..d122c1a03 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java @@ -90,9 +90,9 @@ private WebHookAction onGetStatusPng(Job project, StaplerRequest request) private WebHookAction onPost(Job project, StaplerRequest request) { String requestBody = getRequestBody(request); String eventHeader = request.getHeader("X-Gitlab-Event"); - if (eventHeader.equals("Merge Request Hook")) { + if ("Merge Request Hook".equals(eventHeader)) { return new MergeRequestBuildAction(project, requestBody); - } else if (eventHeader.equals("Push Hook")) { + } else if ("Push Hook".equals(eventHeader)) { return new PushBuildAction(project, requestBody); } LOGGER.log(Level.FINE, "Unsupported event header: {0}", eventHeader); From 986851c5f2b59592847c1a47a842067300b1859a Mon Sep 17 00:00:00 2001 From: Hendrik Coetzee Date: Wed, 4 May 2016 10:18:36 +0200 Subject: [PATCH 2/2] Modified to utilize StringUtils, as requested by @coder-hugo --- .../com/dabsquared/gitlabjenkins/webhook/ActionResolver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java b/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java index d122c1a03..79e826cb4 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/webhook/ActionResolver.java @@ -17,6 +17,7 @@ import hudson.util.HttpResponses; import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -90,9 +91,9 @@ private WebHookAction onGetStatusPng(Job project, StaplerRequest request) private WebHookAction onPost(Job project, StaplerRequest request) { String requestBody = getRequestBody(request); String eventHeader = request.getHeader("X-Gitlab-Event"); - if ("Merge Request Hook".equals(eventHeader)) { + if (StringUtils.equals(eventHeader, "Merge Request Hook") ) { return new MergeRequestBuildAction(project, requestBody); - } else if ("Push Hook".equals(eventHeader)) { + } else if ( StringUtils.equals(eventHeader,"Push Hook")) { return new PushBuildAction(project, requestBody); } LOGGER.log(Level.FINE, "Unsupported event header: {0}", eventHeader);