FindBugs: StepNode.getDescriptor can be null.
@@ -5,21 +5,21 @@ import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
-import hudson.tasks.test.PipelineTestDetails;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.junit.TestResultSummary;
+import hudson.tasks.test.PipelineTestDetails;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nonnull;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
+import org.jenkinsci.plugins.workflow.graph.StepNode;
import org.jenkinsci.plugins.workflow.steps.StepContext;
+import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
-import javax.annotation.Nonnull;
-import java.util.ArrayList;
-import java.util.List;
-import org.jenkinsci.plugins.workflow.graph.StepNode;
-
public class JUnitResultsStepExecution extends SynchronousNonBlockingStepExecution<TestResultSummary> {
private transient final JUnitResultsStep step;
@@ -69,7 +69,7 @@ public class JUnitResultsStepExecution extends SynchronousNonBlockingStepExecuti
List<FlowNode> enclosingBlocks = new ArrayList<>();
for (FlowNode enclosing : node.getEnclosingBlocks()) {
if (enclosing != null && enclosing.getAction(LabelAction.class) != null) {
- if ((enclosing instanceof StepNode && ((StepNode) enclosing).getDescriptor().getFunctionName().equals("stage")) ||
+ if (isStageNode(enclosing) ||
(enclosing.getAction(ThreadNameAction.class) != null)) {
enclosingBlocks.add(enclosing);
}
@@ -79,6 +79,15 @@ public class JUnitResultsStepExecution extends SynchronousNonBlockingStepExecuti
return enclosingBlocks;
}
+ private static boolean isStageNode(@Nonnull FlowNode node) {
+ if (node instanceof StepNode) {
+ StepDescriptor d = ((StepNode) node).getDescriptor();
+ return d != null && d.getFunctionName().equals("stage");
+ } else {
+ return false;
+ }
+ }
+
@Nonnull
public static List<String> getEnclosingBlockIds(@Nonnull List<FlowNode> nodes) {
List<String> ids = new ArrayList<>();
