-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Prevent infinite loop in RootLocator when .mvn directory exists in subdirectory (fixes #11321) #11323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gnodet
merged 3 commits into
apache:master
from
gnodet:fix/mng-11321-root-locator-infinite-loop
Oct 28, 2025
Merged
Prevent infinite loop in RootLocator when .mvn directory exists in subdirectory (fixes #11321) #11323
gnodet
merged 3 commits into
apache:master
from
gnodet:fix/mng-11321-root-locator-infinite-loop
Oct 28, 2025
Conversation
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
2e009b9 to
5f8f14d
Compare
5f8f14d to
3e9b0a7
Compare
3e9b0a7 to
18b384f
Compare
cstamas
approved these changes
Oct 27, 2025
This is a partial fix that adds validation to prevent reading parent POMs that are located above the discovered root directory. This prevents infinite loops when a .mvn directory exists in a subdirectory and Maven is invoked with -f pointing to that subdirectory. The fix includes: - Validation in doReadFileModel() to check parent POM location - Validation in getEnhancedProperties() to prevent infinite loops - Helper method isParentWithinRootDirectory() for path validation - Integration test to reproduce and verify the fix However, the infinite loop issue is still occurring in getEnhancedProperties and needs further investigation.
The .mvn directory needs to contain at least one file to be a proper root marker. Adding an empty extensions.xml file to make the test more realistic and ensure the .mvn directory is properly recognized.
eecceb9 to
efe734e
Compare
gnodet
added a commit
to gnodet/maven
that referenced
this pull request
Oct 28, 2025
…bdirectory (fixes apache#11321) (apache#11323) This is a fix that adds validation to prevent reading parent POMs that are located above the discovered root directory. This prevents infinite loops when a .mvn directory exists in a subdirectory and Maven is invoked with -f pointing to that subdirectory. The fix includes: - Validation in doReadFileModel() to check parent POM location - Validation in getEnhancedProperties() to prevent infinite loops - Helper method isParentWithinRootDirectory() for path validation - Integration test to reproduce and verify the fix (cherry picked from commit 714fc51)
Contributor
Author
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
gnodet
added a commit
that referenced
this pull request
Oct 29, 2025
…y exists in subdirectory (fixes #11321) (#11323) (#11350) This is a fix that adds validation to prevent reading parent POMs that are located above the discovered root directory. This prevents infinite loops when a .mvn directory exists in a subdirectory and Maven is invoked with -f pointing to that subdirectory. The fix includes: - Validation in doReadFileModel() to check parent POM location - Validation in getEnhancedProperties() to prevent infinite loops - Helper method isParentWithinRootDirectory() for path validation - Integration test to reproduce and verify the fix (cherry picked from commit 714fc51)
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.
Description
Fixes #11321
When Maven is invoked with
-fpointing to a subdirectory that contains a.mvndirectory, the RootLocator would get into an infinite loop, causing a StackOverflowError.Root Cause
The issue was in
DefaultRootLocator.findRoot()which didn't check if it had reached the filesystem root before continuing to recurse upward. When a.mvndirectory exists in a subdirectory and Maven is invoked with-fpointing to that subdirectory, the locator would keep recursing up the tree indefinitely.Solution
The fix adds a check to detect when we've reached the filesystem root by comparing if the parent path equals the current path. When the filesystem root is reached without finding a root directory, the method now correctly returns
nullas specified by the@Nullableannotation on the interface.Changes
Modified:
impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.javafindRoot()method to check for filesystem rootnullwhen no root is found (as per interface contract)Added: Unit tests in
impl/maven-impl/src/test/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocatorTest.javaAdded: Integration test in
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11321Test.javagh-11321naming conventionAdded: Test resources for the integration test
.mvnin subdirectoryUpdated: JavaDoc for
RootLocatorinterface methodsfindRoot()andfindMandatoryRoot()methodsfindRoot()returnsnullwhen no root is foundfindMandatoryRoot()throws an exception when no root is foundTesting
-fpointing to a subdirectory containing.mvnnullwhen no root directory is found, which is the expected behavior according to the interface contractPull Request opened by Augment Code with guidance from the PR author