You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
StackOverflowError in DefaultModelBuilder.readFileModel with recursive parent resolution #12301
Building jackrabbit-filevault with Maven from the maven-4.0.x branch causes a StackOverflowError in DefaultModelBuilder$ModelBuilderSessionState.readFileModel.
The stack shows infinite recursion through this cycle:
at org.apache.maven.impl.model.DefaultModelBuilder$ModelBuilderSessionState.cache(DefaultModelBuilder.java:2140)
at org.apache.maven.impl.model.DefaultModelBuilder$ModelBuilderSessionState.readFileModel(DefaultModelBuilder.java:1484)
at org.apache.maven.impl.model.DefaultModelBuilder$ModelBuilderSessionState.getEnhancedProperties(DefaultModelBuilder.java:705)
at org.apache.maven.impl.model.DefaultModelBuilder$ModelBuilderSessionState.doReadFileModel(DefaultModelBuilder.java:1653)
at org.apache.maven.impl.model.DefaultModelBuilder$ModelBuilderSessionState.lambda\$cache\$14(DefaultModelBuilder.java:2140)
at org.apache.maven.impl.cache.AbstractRequestCache.request(AbstractRequestCache.java:69)
... (repeating)
Inside doReadFileModel(rootPOM) (line ~1579–1601):
The parent version ${revision} sets versionContainsExpression = true, so it resolves the parent path and calls: derive(parent/pom.xml).readFileModel() → cache(parent/pom.xml, FILE, doReadFileModel) — new cache entry, starts computing
Inside doReadFileModel(parent/pom.xml) (line 1653): getEnhancedProperties(parentModel, rootDirectory) is called.
Since parent/pom.xml is not the root (/filevault/parent/ ≠ /filevault/), it takes the non-root branch (line 703–706):
readFileModel(rootPOM) → cache(rootPOM, FILE, ...) — same key as step 1! CachingSupplier detects re-entrancy: value == null && computingThread == currentThread → throws CyclicCacheAccessException
AbstractRequestCache.request() catches CyclicCacheAccessException and calls supplier.apply(req) directly (line 69), bypassing the cache. This re-invokes doReadFileModel(rootPOM) without any guard.
doReadFileModel(rootPOM) again (step 2 repeats): parent version has ${revision} → tries to read parent/pom.xml → cache(parent/pom.xml, FILE, ...) — same key as step 3! CyclicCacheAccessException again → doReadFileModel(parent/pom.xml) called directly
Why the CyclicCacheAccessException Fallback Makes It Worse
AbstractRequestCache.request() catches CyclicCacheAccessException and falls back to calling the supplier directly. The comment says this is to handle batch/singular re-entrant access. But in this context it is the wrong escape hatch: calling supplier.apply(req) on doReadFileModel doesn't terminate — it just re-enters the same computation that caused the exception, starting the whole cycle over with one more frame on the stack.
Two Interacting Root Causes
getEnhancedProperties reads the root model via readFileModel (line 705), which triggers the full doReadFileModel pipeline including another call to getEnhancedProperties. For a non-root module whose parent IS the root POM, this creates a circular read dependency: doReadFileModel(parent/) → getEnhancedProperties → readFileModel(root) → doReadFileModel(root) → readFileModel(parent/) → ...
doReadFileModel reads the parent POM to resolve CI-friendly version coordinates (line 1601, when versionContainsExpression), which for the root POM triggers reading the internal parent module. Combined with (1), these two loops interlock into an unbounded cycle.
Suggested Fix
The cleanest fix is to make getEnhancedProperties perform a lightweight property-only read of the root model rather than calling the full readFileModel() pipeline:
// In getEnhancedProperties(), instead of:ModelrootModel = derive(Sources.buildSource(rootModelPath)).readFileModel();
// Use a lightweight read that extracts only properties (no parent resolution, no getEnhancedProperties call):ModelrootModel = derive(Sources.buildSource(rootModelPath)).readRawXmlPropertiesOnly();
Alternatively, add a depth guard / in-progress set to getEnhancedProperties so that if it is already being executed for a given source path on the current call chain it returns early (skipping the recursive root model read). A thread-local Set<Path> of "currently resolving" paths in getEnhancedProperties would suffice.
The CyclicCacheAccessException fallback itself might also need to be re-examined: re-running the full supplier without a guard means any cycle that goes through that path will stack-overflow rather than produce a meaningful error.
Analyzed from the Maven source at impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java and impl/maven-impl/src/main/java/org/apache/maven/impl/cache/AbstractRequestCache.java. The critical methods are doReadFileModel (lines 1491–1705), getEnhancedProperties (lines 676–714), and AbstractRequestCache.request (lines 61–71).
Activity
gnodet commentedon Jun 18, 2026
Root Cause Analysis
The Project Pattern That Triggers This
Jackrabbit FileVault uses an internal parent anti-pattern in combination with CI-friendly versions:
pom.xml) declares<parent>pointing toparent/pom.xml(a reactor module in the same repo)<version>${revision}</version>.mvn/lives at the repo root, sosession.getRootDirectory()= the directory ofpom.xmlThe Exact Recursion Cycle
The cycle involves two interacting feedback loops exposed by how
CyclicCacheAccessExceptionis handled.Step-by-step trace (all on one thread):
loadFilePomcallsreadFileModel(rootPOM)→cache(rootPOM, FILE, doReadFileModel)— cache miss, starts computing,CachingSuppliermarkscomputingThread = currentThreadInside
doReadFileModel(rootPOM)(line ~1579–1601):The parent version
${revision}setsversionContainsExpression = true, so it resolves the parent path and calls:derive(parent/pom.xml).readFileModel()→cache(parent/pom.xml, FILE, doReadFileModel)— new cache entry, starts computingInside
doReadFileModel(parent/pom.xml)(line 1653):getEnhancedProperties(parentModel, rootDirectory)is called.Since
parent/pom.xmlis not the root (/filevault/parent/≠/filevault/), it takes the non-root branch (line 703–706):readFileModel(rootPOM)→cache(rootPOM, FILE, ...)— same key as step 1!CachingSupplierdetects re-entrancy:value == null && computingThread == currentThread→ throwsCyclicCacheAccessExceptionAbstractRequestCache.request()catchesCyclicCacheAccessExceptionand callssupplier.apply(req)directly (line 69), bypassing the cache. This re-invokesdoReadFileModel(rootPOM)without any guard.doReadFileModel(rootPOM)again (step 2 repeats): parent version has${revision}→ tries to readparent/pom.xml→cache(parent/pom.xml, FILE, ...)— same key as step 3!CyclicCacheAccessExceptionagain →doReadFileModel(parent/pom.xml)called directlydoReadFileModel(parent/pom.xml)again (step 3 repeats):getEnhancedProperties→readFileModel(rootPOM)→ step 4 repeats → step 5 repeats → step 6...Steps 5→6→7→5→6→7→... until
StackOverflowError.Why the
CyclicCacheAccessExceptionFallback Makes It WorseAbstractRequestCache.request()catchesCyclicCacheAccessExceptionand falls back to calling the supplier directly. The comment says this is to handle batch/singular re-entrant access. But in this context it is the wrong escape hatch: callingsupplier.apply(req)ondoReadFileModeldoesn't terminate — it just re-enters the same computation that caused the exception, starting the whole cycle over with one more frame on the stack.Two Interacting Root Causes
getEnhancedPropertiesreads the root model viareadFileModel(line 705), which triggers the fulldoReadFileModelpipeline including another call togetEnhancedProperties. For a non-root module whose parent IS the root POM, this creates a circular read dependency:doReadFileModel(parent/) → getEnhancedProperties → readFileModel(root) → doReadFileModel(root) → readFileModel(parent/) → ...doReadFileModelreads the parent POM to resolve CI-friendly version coordinates (line 1601, whenversionContainsExpression), which for the root POM triggers reading the internal parent module. Combined with (1), these two loops interlock into an unbounded cycle.Suggested Fix
The cleanest fix is to make
getEnhancedPropertiesperform a lightweight property-only read of the root model rather than calling the fullreadFileModel()pipeline:Alternatively, add a depth guard / in-progress set to
getEnhancedPropertiesso that if it is already being executed for a given source path on the current call chain it returns early (skipping the recursive root model read). A thread-localSet<Path>of "currently resolving" paths ingetEnhancedPropertieswould suffice.The
CyclicCacheAccessExceptionfallback itself might also need to be re-examined: re-running the full supplier without a guard means any cycle that goes through that path will stack-overflow rather than produce a meaningful error.Analyzed from the Maven source at
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.javaandimpl/maven-impl/src/main/java/org/apache/maven/impl/cache/AbstractRequestCache.java. The critical methods aredoReadFileModel(lines 1491–1705),getEnhancedProperties(lines 676–714), andAbstractRequestCache.request(lines 61–71).[#12301] Fix StackOverflowError with internal parent and CI-friendly …
[#12301] Fix StackOverflowError with internal parent and CI-friendly …
Revert "[#12301] Fix StackOverflowError with internal parent and CI-f…
[#12301] Use stack-passed Set instead of shared ConcurrentHashMap for…
[#12301] Fix StackOverflowError with internal parent and CI-friendly …