Skip to content

GROOVY-12163: fix concurrent modification of ExpandoMetaClass mixinClasses#2708

Merged
paulk-asert merged 2 commits into
apache:masterfrom
paulk-asert:groovy12163
Jul 13, 2026
Merged

GROOVY-12163: fix concurrent modification of ExpandoMetaClass mixinClasses#2708
paulk-asert merged 2 commits into
apache:masterfrom
paulk-asert:groovy12163

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

Provides ticket number and improves test for #2698

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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’s mixinClasses backing set with CopyOnWriteArraySet to 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.

Comment thread src/test/groovy/groovy/lang/ExpandoMetaClassMixinConcurrencyTest.groovy Outdated
…asses (tweak test for improved robustness and less cost and fix a misleading comment)
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.1108%. Comparing base (86c6648) to head (b94cb8c).

Files with missing lines Patch % Lines
...g/codehaus/groovy/reflection/MixinInMetaClass.java 0.0000% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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                
Files with missing lines Coverage Δ
src/main/java/groovy/lang/ExpandoMetaClass.java 77.1376% <100.0000%> (+0.3718%) ⬆️
...g/codehaus/groovy/reflection/MixinInMetaClass.java 81.3333% <0.0000%> (-1.3333%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Jul 13, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: b94cb8c
▶️ Tests: 103507 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

@paulk-asert paulk-asert merged commit 535be21 into apache:master Jul 13, 2026
32 checks passed
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.

4 participants