gnodet opened a new pull request, #11323:
URL: https://github.com/apache/maven/pull/11323

   ## Description
   
   Fixes #11321
   
   When Maven is invoked with `-f` pointing to a subdirectory that contains a 
`.mvn` directory, 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 
`.mvn` directory exists in a subdirectory and Maven is invoked with `-f` 
pointing 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 returns the 
starting path instead of continuing to recurse.
   
   ## Changes
   
   1. **Modified**: 
`impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java`
      - Updated `findRoot()` method to check for filesystem root
      - Returns starting path when no root is found
   
   2. **Added**: Unit tests in 
`impl/maven-impl/src/test/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocatorTest.java`
      - Tests for various scenarios including the infinite loop case
      - All 7 tests pass
   
   3. **Added**: Integration test in 
`its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng11321RootLocatorInfiniteLoopTest.java`
      - Reproduces the original issue
      - Verifies the fix works correctly
   
   4. **Added**: Test resources for the integration test
      - Directory structure with `.mvn` in subdirectory
      - POM files for testing
   
   ## Testing
   
   - Unit tests: All 7 tests pass
   - The fix prevents the StackOverflowError when running Maven with `-f` 
pointing to a subdirectory containing `.mvn`
   - The starting path is returned when no root directory is found, which is 
the expected behavior
   
   ---
   Pull Request opened by [Augment Code](https://www.augmentcode.com/) with 
guidance from the PR author


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to