Skip to content
Permalink
Browse files
[FIXED JENKINS-38167] NPE from scripts using @field with instance ini…
…tializers loading properties.
  • Loading branch information
jglick committed Sep 13, 2016
1 parent dafdb7f commit adc9b4cf81be93159f9292b3e0bdbc911da69243
Showing with 18 additions and 0 deletions.
  1. +5 −0 src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java
  2. +13 −0 src/test/java/org/jenkinsci/plugins/workflow/cps/CpsScriptTest.java
@@ -144,6 +144,11 @@ public Object getProperty(String property) {
}

public @CheckForNull Run<?,?> $buildNoException() {
if (execution == null) {
// Still inside the WorkflowScript constructor, e.g. because getProperty is being called from a @Field.
// In such cases we do not expect to be able to use library variables, so just skip it.
return null;
}
try {
return $build();
} catch (IOException x) {
@@ -11,6 +11,7 @@
import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

public class CpsScriptTest extends AbstractCpsFlowTest {
/**
@@ -100,4 +101,16 @@ private String dumpError() {
}
return msg.toString();
}

@Issue("JENKINS-38167")
@Test public void bindingDuringConstructor() throws Exception {
CpsFlowDefinition flow = new CpsFlowDefinition("@groovy.transform.Field def opt = (binding.hasVariable('opt')) ? opt : 'default'");
createExecution(flow);
exec.start();
while (!exec.isComplete()) {
exec.waitForSuspension();
}
assertEquals(dumpError(), Result.SUCCESS, exec.getResult());
}

}

0 comments on commit adc9b4c

Please sign in to comment.