Skip to content

fix: handle null FlowExecution in PipelineLogExtractor#97

Merged
shenxianpeng merged 2 commits intojenkinsci:mainfrom
lidiams96:fix/null-flow-execution-npe
Feb 17, 2026
Merged

fix: handle null FlowExecution in PipelineLogExtractor#97
shenxianpeng merged 2 commits intojenkinsci:mainfrom
lidiams96:fix/null-flow-execution-npe

Conversation

@lidiams96
Copy link
Contributor

Environment

Steps to Reproduce

  1. Install the plugin and configure a Bedrock (or any) provider
  2. Run a pipeline that fails early or where WorkflowRun.getExecution() returns null
  3. The plugin attempts to walk the flow graph via PipelineLogExtractor.getFailedStepLog()
  4. FlowGraphWalker receives a null execution and throws NullPointerException

Reproduced locally with mvn hpi:run when running a simple failing pipeline — the WorkflowRun.getExecution() returned null because the execution context was not fully initialized.

Expected Behavior

The plugin should gracefully fall back to the overall build log (run.getLog(maxLines)) when no flow execution is available, consistent with its existing behavior for non-pipeline builds.

Actual Behavior

java.lang.NullPointerException: Cannot invoke "org.jenkinsci.plugins.workflow.flow.FlowExecution.getCurrentHeads()" because "exec" is null

Fix

Added a null check for FlowExecution before creating FlowGraphWalker. When execution is null, the method falls back to run.getLog(maxLines) — the same fallback used when no failed step log is found or when the build is not a pipeline.

FlowExecution execution = ((WorkflowRun) this.run).getExecution();
if (execution == null) {
    setUrl("0");
    return run.getLog(maxLines);
}

This can happen in several scenarios:

  • Pipeline execution has not started yet (very early failure)
  • Execution was cleaned up by garbage collection
  • Local test environments (mvn hpi:run) where the pipeline context is not fully initialized

WorkflowRun.getExecution() can return null when the pipeline execution
has not yet started, was interrupted very early, or has been cleaned up.
Without this check, FlowGraphWalker throws a NullPointerException.

Fall back to the overall build log when execution is null, which is
consistent with the existing fallback behavior for non-pipeline builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lidiams96 lidiams96 requested a review from a team as a code owner February 17, 2026 11:30
@shenxianpeng shenxianpeng requested review from Copilot and removed request for a team February 17, 2026 11:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a NullPointerException that occurs when WorkflowRun.getExecution() returns null during pipeline log extraction. The fix adds a defensive null check before creating FlowGraphWalker, allowing the plugin to gracefully fall back to the overall build console log instead of crashing. This scenario can occur when pipeline execution hasn't fully initialized, has been cleaned up by garbage collection, or in local test environments.

Changes:

  • Added null check for FlowExecution before creating FlowGraphWalker in PipelineLogExtractor.getFailedStepLog()
  • Graceful fallback to run.getLog(maxLines) when execution is null, consistent with existing fallback behavior for non-pipeline builds

Add test coverage for the null FlowExecution guard:
- testNullFlowExecutionFallsBackToBuildLog: verifies that a
  WorkflowRun with null execution falls back to run.getLog()
  without throwing NullPointerException
- testNonPipelineBuildFallsBackToBuildLog: verifies that non-pipeline
  builds (FreeStyleBuild) also fall back correctly

Add mockito-core as a test dependency to enable mocking WorkflowRun.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shenxianpeng shenxianpeng added the bug For changelog: Minor bug. Will be listed after features label Feb 17, 2026
Copy link
Member

@shenxianpeng shenxianpeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@shenxianpeng shenxianpeng merged commit 28ee969 into jenkinsci:main Feb 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug For changelog: Minor bug. Will be listed after features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments