Skip to content

Commit

Permalink
Fix potential NPE.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed May 20, 2024
1 parent 7533790 commit 6db5876
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/main/java/io/jenkins/plugins/util/AbstractExecution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Objects;
import java.util.Optional;

import edu.hm.hafner.util.Ensure;

import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
Expand Down Expand Up @@ -174,8 +173,6 @@ private PipelineResultHandler createPipelineResultHandler() throws IOException,
private FlowNode getFlowNode() throws IOException, InterruptedException {
var flowNode = getContext().get(FlowNode.class);

Ensure.that(flowNode).isNotNull("FlowNode is not defined in the context of " + this);

return flowNode;
return Objects.requireNonNull(flowNode, "FlowNode is not defined in the context of " + this);

Check warning on line 176 in src/main/java/io/jenkins/plugins/util/AbstractExecution.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 170-176 are not covered by tests

Check warning on line 176 in src/main/java/io/jenkins/plugins/util/AbstractExecution.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

NORMAL: Possible null pointer dereference in io.jenkins.plugins.util.AbstractExecution.getFlowNode() due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>
}
}

0 comments on commit 6db5876

Please sign in to comment.