Skip to content

[#12301] Fix StackOverflowError with internal parent and CI-friendly revision - #12323

Merged
gnodet merged 2 commits into
masterfrom
capable-arrhinceratops
Jun 19, 2026
Merged

gnodet merged 2 commits into
masterfrom
capable-arrhinceratops

Conversation

@gnodet

@gnodet gnodet commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Re-forward-port of the GH-12301 fix from maven-4.0.x to master. The previous forward-port (#12317) was reverted because it broke ConsumerPomBuilderTest.testSimpleConsumer.

Root cause of the breakage: The original fix used a shared ConcurrentHashMap.newKeySet() (activeModelReads) to track which POM files were being read by doReadFileModel(). When PhasingExecutor processes subprojects in parallel via loadFilePom(), thread A adding a path to the shared set would cause thread B's getEnhancedProperties() to skip reading that same model — even though there was no actual recursion, just parallel reads.

Fix: Replace the shared ConcurrentHashMap.newKeySet() with a ThreadLocal<Set<Path>>. Each thread tracks only its own call stack, preventing actual recursive cycles (the StackOverflowError from GH-12301) without blocking legitimate parallel reads across threads.

  • ThreadLocal<Set<Path>> activeModelReads is added to ModelBuilderSessionState and shared across all derive()-d sessions
  • doReadFileModel() adds/removes the current path from the thread-local set
  • getEnhancedProperties() checks the thread-local set before reading the root model

Test plan

  • ConsumerPomBuilderTest (7 tests) — the test broken by the previous forward-port
  • DefaultModelBuilderTest (12 tests) — model builder tests
  • MavenITgh12301StackOverflowInternalParentRevisionTest — IT for the original issue

Closes #12301

Fully automatic review from Claude Code

gnodet and others added 2 commits June 19, 2026 08:36
…revision

Re-forward-port the GH-12301 fix from maven-4.0.x to master, using
ThreadLocal<Set<Path>> instead of the shared ConcurrentHashMap.newKeySet()
that caused a race condition with PhasingExecutor parallel model loading.

The original forward-port (#12317) used a shared set to track which POM files
were being read by doReadFileModel(). This prevented the StackOverflowError
from GH-12301, but caused false cycle detection when parallel threads in
loadFilePom() read the same model simultaneously — breaking
ConsumerPomBuilderTest.testSimpleConsumer.

The fix uses ThreadLocal so each thread tracks only its own call stack,
preventing actual recursive cycles within the same thread without blocking
legitimate parallel reads across threads.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ocal

Replace ThreadLocal<Set<Path>> with a stack-passed Set<Path> parameter
threaded through readFileModel() → doReadFileModel() → getEnhancedProperties().
Each readFileModel() entry point creates a fresh HashSet, avoiding any
shared mutable state between concurrent model-loading threads.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@gnodet
gnodet requested a review from cstamas June 19, 2026 08:23
@gnodet
gnodet merged commit 4ff2209 into master Jun 19, 2026
23 checks passed
@gnodet
gnodet deleted the capable-arrhinceratops 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.1.0 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.

StackOverflowError in DefaultModelBuilder.readFileModel with recursive parent resolution

1 participant