GROOVY-12163: fix concurrent modification of ExpandoMetaClass mixinClasses#2708
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a concurrency bug in ExpandoMetaClass mixin handling where concurrent mixin additions could throw ConcurrentModificationException during method dispatch, by switching the underlying mixin set to a thread-safe implementation and adding a regression test.
Changes:
- Replace
ExpandoMetaClass’smixinClassesbacking set withCopyOnWriteArraySetto support concurrent iteration + structural modification. - Add a new concurrency regression test that exercises concurrent mixin addition while dispatch scans mixins.
- Clarify
MixinInMetaClass#hashCode()documentation in relation to mixin deduplication behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/java/groovy/lang/ExpandoMetaClass.java | Switch mixinClasses from LinkedHashSet to CopyOnWriteArraySet to avoid concurrent modification during dispatch. |
| src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java | Expand Javadoc around hashCode() in the context of mixin deduplication. |
| src/test/groovy/groovy/lang/ExpandoMetaClassMixinConcurrencyTest.groovy | Add a concurrency test intended to reproduce/guard against concurrent mixin-add vs dispatch iteration issues. |
…asses (tweak test for improved robustness and less cost and fix a misleading comment)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2708 +/- ##
==================================================
+ Coverage 69.1077% 69.1108% +0.0031%
Complexity 34235 34235
==================================================
Files 1537 1537
Lines 129356 129356
Branches 23503 23503
==================================================
+ Hits 89395 89399 +4
+ Misses 31941 31937 -4
Partials 8020 8020
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: b94cb8c Learn more about TestLens at testlens.app. |
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.
Provides ticket number and improves test for #2698