Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlowExecution.getOwner left null after WorkflowRun.reload #472

Merged
merged 10 commits into from
Nov 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@

// super.reload() forces result to be FAILURE, so working around that
new XmlFile(XSTREAM,new File(getRootDir(),"build.xml")).unmarshal(this);
synchronized (getMetadataGuard()) {
if (Boolean.TRUE.equals(completed) && execution != null && executionLoaded) {
execution.onLoad(new Owner(this));

Check warning on line 558 in src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH

HIGH: Possible null pointer dereference of WorkflowRun.execution in org.jenkinsci.plugins.workflow.job.WorkflowRun.reload()
Raw output
<p> There is a branch of statement that, <em>if executed,</em> guarantees that a null value will be dereferenced, which would generate a <code>NullPointerException</code> when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception can't ever be executed; deciding that is beyond the ability of SpotBugs. </p>
}
}
}

@Override protected void onLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyArray;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -618,6 +619,15 @@ private static String checkoutString(GitSampleRepoRule repo, boolean changelog,
", userRemoteConfigs: [[url: $/" + repo.fileUrl() + "/$]]])\n";
}

@Test public void reloadOwner() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "reloadOwner");
p.setDefinition(new CpsFlowDefinition("", true));
WorkflowRun b = r.buildAndAssertSuccess(p);
assertThat("right owner before reload", b.getExecution().getOwner(), is(b.asFlowExecutionOwner()));
b.reload();
assertThat("right owner after reload", b.getExecution().getOwner(), is(b.asFlowExecutionOwner()));
}

// This test is to ensure that the shortDescription on the CancelCause is escaped properly on summary.jelly
@Issue("SECURITY-3042")
@Test public void escapedDisplayNameAfterAbort() throws Exception {
Expand Down
Loading