Skip to content

Commit

Permalink
[FIXED JENKINS-38167] NPE from scripts using @field with instance ini…
Browse files Browse the repository at this point in the history
…tializers loading properties.
  • Loading branch information
jglick committed Sep 13, 2016
1 parent dafdb7f commit adc9b4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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.