fix: handle null FlowExecution in PipelineLogExtractor#97
Merged
shenxianpeng merged 2 commits intojenkinsci:mainfrom Feb 17, 2026
Merged
fix: handle null FlowExecution in PipelineLogExtractor#97shenxianpeng merged 2 commits intojenkinsci:mainfrom
shenxianpeng merged 2 commits intojenkinsci:mainfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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
FlowExecutionbefore creatingFlowGraphWalkerinPipelineLogExtractor.getFailedStepLog() - Graceful fallback to
run.getLog(maxLines)when execution is null, consistent with existing fallback behavior for non-pipeline builds
src/main/java/io/jenkins/plugins/explain_error/PipelineLogExtractor.java
Show resolved
Hide resolved
src/main/java/io/jenkins/plugins/explain_error/PipelineLogExtractor.java
Show resolved
Hide resolved
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Environment
mvn hpi:run)Steps to Reproduce
WorkflowRun.getExecution()returnsnullPipelineLogExtractor.getFailedStepLog()FlowGraphWalkerreceives anullexecution and throwsNullPointerExceptionReproduced locally with
mvn hpi:runwhen running a simple failing pipeline — theWorkflowRun.getExecution()returnednullbecause 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
Fix
Added a null check for
FlowExecutionbefore creatingFlowGraphWalker. Whenexecutionisnull, the method falls back torun.getLog(maxLines)— the same fallback used when no failed step log is found or when the build is not a pipeline.This can happen in several scenarios:
mvn hpi:run) where the pipeline context is not fully initialized