Fix concurrent modification exception in ExecuteDslScripts #1253
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.
This PR fixes an intermittant problem we've been seeing on our builds, where alternate builds fail because of
ConcurrentModificationException
inExecuteDslScripts
. This was raised as JENKINS-69064.Explanation
As part of the cleanup of removed templates in the
updateTemplates()
method, all seed job references are read for the removed template. These references are then filtered to those matching the seed job name. These matches are then removed from the seed job references.However, the filtered references are a 'live' view (from
Collections2.filter
) based on the original seed job references, so attempting to remove them results in aConcurrentModificationException
.Fix
The fix simply first converts the 'live' matches collection to a hash set before passing it to
removeAll()
, which allows the original collection to be modified. A unit test has been added to confirm this.Link to relevant pull requests, esp. upstream and downstream changes