Skip to content

Commit

Permalink
[JENKINS-49433] - Prevent NPEs in JobDSL ConditionContext operations.
Browse files Browse the repository at this point in the history
Fixes the following operations: `selfPromotion()`, `parameterizedSelfPromotion()`, `downstream()`
  • Loading branch information
oleg-nenashev committed Feb 12, 2018
1 parent 3849c36 commit f0363e9
Showing 1 changed file with 11 additions and 9 deletions.
Expand Up @@ -11,6 +11,8 @@

import javaposse.jobdsl.plugin.DslEnvironment;

import javax.annotation.CheckForNull;

import static javaposse.jobdsl.plugin.ContextExtensionPoint.executeInContext;

public class ConditionsContext implements Context {
Expand Down Expand Up @@ -56,17 +58,17 @@ public ConditionsContext(DslEnvironment dslEnvironment) {
this.dslEnvironment = dslEnvironment;
}

public void selfPromotion(Boolean evenIfUnstable) {
public void selfPromotion(@CheckForNull Boolean evenIfUnstable) {
isSelfPromotion = true;
if (evenIfUnstable) {
this.evenIfUnstable = evenIfUnstable;
if (evenIfUnstable != null && evenIfUnstable) {
this.evenIfUnstable = true;
}
}

public void parameterizedSelfPromotion(Boolean evenIfUnstable, String parameterName, String parameterValue) {
public void parameterizedSelfPromotion(@CheckForNull Boolean evenIfUnstable, String parameterName, String parameterValue) {
isParameterizedSelfPromotion = true;
if (evenIfUnstable) {
this.isParameterizedSelfPromotion = evenIfUnstable;
if (evenIfUnstable != null && evenIfUnstable) {
this.isParameterizedSelfPromotion = true;
}
this.parameterName = parameterName;
this.parameterValue = parameterValue;
Expand Down Expand Up @@ -94,10 +96,10 @@ public void parameters(Closure<?> parametersClosure) {
params.putAll(parametersContext.getBuildParameterNodes());
}

public void downstream(Boolean evenIfUnstable, String jobs) {
public void downstream(@CheckForNull Boolean evenIfUnstable, String jobs) {
isDownstreamPass = true;
if (evenIfUnstable) {
this.evenIfUnstableDownstream = evenIfUnstable;
if (evenIfUnstable != null && evenIfUnstable) {
this.evenIfUnstableDownstream = true;
}
this.jobs = jobs;
}
Expand Down

0 comments on commit f0363e9

Please sign in to comment.