arturobernalg opened a new pull request, #2241:
URL: https://github.com/apache/maven-resolver/pull/2241

   A dependency graph in FULL verbosity mode can contain a node that depends on 
an ancestor of itself. DependencyGraphDumper has no cycle protection, so it 
recurses forever on such a graph. The documented workaround, wrapping it in 
TreeDependencyVisitor, avoids the crash but tracks every node ever visited 
anywhere in the graph, not just the current path, so a normal diamond 
dependency reached a second time is skipped along with the actual cycle.
   
   CycleAwareDependencyGraphDumper instead tracks only the path from the root 
to the node currently being visited. A node is treated as a cycle only when 
it's already its own ancestor on that path: it gets printed once with a 
"(cycle)" marker and its subtree is cut off (visitEnter returns false), while a 
diamond dependency is still printed in full wherever it occurs.
   
   Getting this right surfaced a latent bug in the existing 
formatIndentation(): it picks out the node currently being formatted by 
comparing it to nodes.peekFirst() with ==. That breaks as soon as the same node 
instance appears twice in the path, which is exactly what happens in a cycle, 
producing garbled indentation. Comparing by position in the walk instead of 
identity fixes it for both dumpers.
   
   Addresses #1561. A previous attempt at this (#1758) ran into review feedback 
on this same class of identity-comparison bug and was closed after going stale; 
this reuses the parent's own path/consumer instead of keeping a second deque, 
so the indentation logic isn't duplicated.
   
   Added CycleAwareDependencyGraphDumperTest: one test builds the existing 
cycles.txt fixture and asserts the exact expected output (fails before the 
formatIndentation fix with garbled indentation), another asserts a cycle-free 
graph dumps identically to the plain DependencyGraphDumper.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [x] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
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