Skip to content

[#12301] Use stack-passed Set for activeModelReads cycle detection - #12325

Merged
gnodet merged 1 commit into
maven-4.0.xfrom
fix/12301-backport-threadlocal-4.0.x
Jun 19, 2026
Merged

gnodet merged 1 commit into
maven-4.0.xfrom
fix/12301-backport-threadlocal-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the shared ConcurrentHashMap.newKeySet() used for activeModelReads cycle detection with a Set<Path> passed through the call stack.

The original fix (PR #12314) used a shared concurrent set across all derived sessions to prevent the StackOverflowError from GH-12301. While this works correctly on maven-4.0.x today, it has a latent race condition: parallel threads in PhasingExecutor (loadFilePom) that read the same model simultaneously can falsely block each other's getEnhancedProperties() from reading that model. This race manifests on master (broke ConsumerPomBuilderTest.testSimpleConsumer when forward-ported as #12317).

The fix passes the Set<Path> as a method parameter through the call chain:

  • doReadFileModel(activeModelReads) → adds current path, passes to both parent resolution and getEnhancedProperties()
  • getEnhancedProperties(model, rootDir, activeModelReads) → checks set before reading root model
  • readFileModel(activeModelReads) → threads the set through the cache call

Each call chain (from readFileModel() entry point) carries its own set, so parallel threads never interfere.

Test plan

  • DefaultModelBuilderTest — 12/12 pass
  • ConsumerPomBuilderTest — 7/7 pass
  • Full IT suite — 1029 pass, 0 failures, 51 skipped

Fully automatic review from Claude Code

… activeModelReads

Replace the shared ConcurrentHashMap.newKeySet() with a Set<Path> passed
through the call stack: doReadFileModel() → getEnhancedProperties() →
readFileModel(). Each call chain carries its own set, preventing recursive
cycles within the same call stack without interfering with parallel threads
in PhasingExecutor.

This avoids the race condition where a path added by one thread blocks a
parallel thread's getEnhancedProperties() from reading that model, while
still preventing the StackOverflowError from GH-12301.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet
gnodet requested a review from cstamas June 19, 2026 08:23
@gnodet
gnodet merged commit 93f76f8 into maven-4.0.x Jun 19, 2026
24 checks passed
@gnodet
gnodet deleted the fix/12301-backport-threadlocal-4.0.x branch June 19, 2026 09:00
@github-actions

Copy link
Copy Markdown
Contributor

@gnodet Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 4.0.0-rc-6 milestone Jun 19, 2026
@gnodet gnodet added the bug Something isn't working label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants