Skip to content

Fix ConcurrentModificationException in getDeclaredResources and getResourcesFromProject#1020

Open
mPokornyETM wants to merge 2 commits intomasterfrom
fix/933-concurrent-modification-exception
Open

Fix ConcurrentModificationException in getDeclaredResources and getResourcesFromProject#1020
mPokornyETM wants to merge 2 commits intomasterfrom
fix/933-concurrent-modification-exception

Conversation

@mPokornyETM
Copy link
Copy Markdown
Contributor

Summary

Fixes ConcurrentModificationException reported in JENKINS-64127 / #933.

Two methods in LockableResourcesManager iterated over the
esources list without synchronization, while other threads could modify it concurrently:

  • \getDeclaredResources()\ — called from CasC/config
  • \getResourcesFromProject()\ — called from \LockRunListener\

Fix

Wrap both methods in \synchronized(syncResources)\ and iterate over \ his.resources\ directly (instead of \ his.getResources()\ which returns an unprotected reference).

Analysis

The original issue listed 10 methods. Of those:

  • 6 were already fixed in previous releases (using \synchronized(syncResources)\ or \getReadOnlyResources())
  • \getResourcesFromBuild()\ was removed entirely
  • \checkCurrentResourcesStatus()\ is private and only called from within an existing \synchronized(syncResources)\ block in \ ryQueue()\
  • 2 remained vulnerable: \getDeclaredResources()\ and \getResourcesFromProject()\ — fixed in this PR

Testing

Existing tests cover both methods (\ConfigurationAsCodeTest, \LockRunListener\ integration tests). All pass.

Fixes #933

@mPokornyETM mPokornyETM requested a review from a team as a code owner April 20, 2026 20:45
@github-actions github-actions Bot added bug java Pull requests that update Java code labels Apr 20, 2026
@mPokornyETM mPokornyETM added the merge-in-3-days-without-review Auto-approve countdown label Apr 20, 2026
@mPokornyETM mPokornyETM force-pushed the fix/933-concurrent-modification-exception branch from 14ee18f to ca0f61d Compare April 20, 2026 21:08
@github-actions github-actions Bot added merge-in-2-days-without-review Auto-approve countdown and removed merge-in-3-days-without-review Auto-approve countdown labels Apr 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Auto-merge countdown: This PR will be auto-approved in 2 day(s) if no review is submitted.

@mPokornyETM mPokornyETM force-pushed the fix/933-concurrent-modification-exception branch from ca0f61d to d5d96f3 Compare April 21, 2026 19:35
@github-actions github-actions Bot added merge-in-1-day-without-review Auto-approve countdown and removed merge-in-2-days-without-review Auto-approve countdown labels Apr 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Auto-merge countdown: This PR will be auto-approved in 1 day(s) if no review is submitted.

…sourcesFromProject

Add synchronized(syncResources) blocks around iterations in
getDeclaredResources() and getResourcesFromProject() to prevent
ConcurrentModificationException when the resources list is modified
concurrently by another thread.

Also changes both methods to iterate over this.resources directly
(inside the sync block) instead of this.getResources() which returns
an unprotected reference.

Fixes #933
@mPokornyETM mPokornyETM force-pushed the fix/933-concurrent-modification-exception branch from d5d96f3 to c595918 Compare April 22, 2026 10:01
@github-actions
Copy link
Copy Markdown
Contributor

⏸️ Auto-merge countdown PAUSED: CI checks are not passing. The countdown will resume when all checks are green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update Java code merge-in-1-day-without-review Auto-approve countdown

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-64127] ConcurrentModificationException from lock step

1 participant