Fix ClassCastException when SCMSource is not GitHubSCMSource#140
Open
kovalevsky wants to merge 1 commit intojenkinsci:masterfrom
Open
Fix ClassCastException when SCMSource is not GitHubSCMSource#140kovalevsky wants to merge 1 commit intojenkinsci:masterfrom
kovalevsky wants to merge 1 commit intojenkinsci:masterfrom
Conversation
The getKey() method in IssueCommentTrigger, LabelAddedTrigger, and PullRequestReviewTrigger performs an unsafe cast of the result of SCMSource.SourceByItem.findSource() to GitHubSCMSource. This throws a ClassCastException when the source is a NullSCMSource (or any other non-GitHub SCM source). This happens during the stop()/start() cycle triggered by MultiBranchProject.processHeadUpdate() when a push event causes BranchProjectFactory.decorate() to call stopTriggers(). The exception in stop() prevents the trigger from being re-registered in start(), silently removing the job from the DescriptorImpl.jobs map. Subsequent webhook events for that PR are then silently ignored because the key lookup returns an empty set. The fix adds instanceof checks before casting in getKey(), returning null when the source is not a GitHubSCMSource, and guards callers in start() and stop() against null keys. A warning is logged to help diagnose similar issues in the future.
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.
Problem
The
getKey()method inIssueCommentTrigger,LabelAddedTrigger, andPullRequestReviewTriggerperforms an unsafe cast of the result ofSCMSource.SourceByItem.findSource()toGitHubSCMSource:This throws a
ClassCastExceptionwhen the source is aNullSCMSource(or any other non-GitHub SCM source):Impact
This happens during the
stop()/start()cycle triggered byMultiBranchProject.processHeadUpdate()when a push event causesBranchProjectFactory.decorate()to callstopTriggers(). The exception instop()prevents the trigger from being re-registered instart(), silently removing the job from theDescriptorImpl.jobsmap. Subsequent webhook events (issue comments, labels, PR reviews) for that PR are then silently ignored because the key lookup returns an empty set.This is particularly hard to diagnose because:
handleIssueCommentmethod just silently returns when the jobs map has no entry for the key)ClassCastExceptionhappens earlier during the push event processing, not during the comment eventFix
Added
instanceofchecks before casting ingetKey(), returningnullwhen the source is not aGitHubSCMSource. Callers instart()andstop()now guard againstnullkeys. A warning is logged when a non-GitHub SCM source is encountered to help diagnose similar issues.The same fix is applied to all three affected trigger classes:
IssueCommentTriggerLabelAddedTriggerPullRequestReviewTrigger