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

   This PR backports the fix from #11106 to the maven-4.0.x branch.
   
   ## Problem
   
   When Maven encounters a cyclic dependency in parent POM resolution (e.g., A 
-> B -> A), it would enter an infinite recursion loop, eventually causing a 
StackOverflowError. This made Maven crash ungracefully without providing useful 
feedback to the user.
   
   ## Solution
   
   The fix implements cycle detection in the `DefaultModelBuilder` by:
   
   1. **Tracking visited parents**: Maintains a set of visited parent 
coordinates during resolution
   2. **Cycle detection**: When a parent that has already been visited is 
encountered again, it indicates a cycle
   3. **Graceful error handling**: Throws a `ModelBuildingException` with a 
clear error message instead of crashing
   
   ## Changes Made
   
   - **Modified `DefaultModelBuilder`**: Added cycle detection logic in parent 
POM resolution methods
   - **Added unit tests**: Comprehensive test case (`ParentCycleDetectionTest`) 
that verifies the fix works correctly
   - **Added integration test**: Integration test 
(`MavenITmng11009StackOverflowParentResolutionTest`) with test resources
   - **Test resources**: Created test POMs with cyclic parent dependencies
   
   ## Testing
   
   The fix includes comprehensive tests that:
   
   - Create scenarios with cyclic parent dependencies (A -> B -> A)
   - Verify that StackOverflowError no longer occurs
   - Confirm that an appropriate cycle detection error is thrown
   - Ensure Maven fails gracefully with a meaningful error message
   - Test that multiple modules with the same parent don't cause false cycle 
detection
   
   ## Backward Compatibility
   
   This change is backward compatible as it only affects error handling for 
invalid POM structures. Valid POMs continue to work as before, while invalid 
cyclic structures now fail gracefully instead of crashing.
   
   ## Related Issues
   
   - Fixes #11009: StackOverflowError in parent POM resolution
   - Backports #11106 to maven-4.0.x branch
   
   ---
   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