Skip to content

fix concurrent modification of ExpandoMetaClass mixinClasses#2698

Open
netliomax25-code wants to merge 1 commit into
apache:masterfrom
netliomax25-code:expandometaclass-mixin-concurrency
Open

fix concurrent modification of ExpandoMetaClass mixinClasses#2698
netliomax25-code wants to merge 1 commit into
apache:masterfrom
netliomax25-code:expandometaclass-mixin-concurrency

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor

Repro: on one thread call metaClass.mixin(someCategory) while another thread dispatches a method on the same class, so findMixinMethod iterates mixinClasses while addMixinClass adds to it.
Cause: mixinClasses is a plain LinkedHashSet with no locking, while every other backing collection in ExpandoMetaClass is a ConcurrentHashMap held alongside the read/write lock. A structural add during iteration throws ConcurrentModificationException in the dispatching thread.
Fix: keep the mixins in a CopyOnWriteArraySet, which is safe for concurrent read-while-modify and preserves insertion order plus the boolean add() dedup that GROOVY-11775 depends on.

Verified with a new test that throws ConcurrentModificationException on the old set and passes with the change; the existing mixin and ExpandoMetaClass suites stay green.

@testlens-app

testlens-app Bot commented Jul 12, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: df5ef75
▶️ Tests: 20760 executed
⚪️ Checks: 23/23 completed


Learn more about TestLens at testlens.app.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant