GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add CycleAwareDependencyGraphDumper to visualize cycles by arturobernalg · Pull Request #2241 · apache/maven-resolver

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Oct 28, 2026

Copy link
Copy Markdown
Member

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
check one of the following:

  • I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004
  • I hereby declare that I have filed an Apache Individual Contributor License Agreement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@arturobernalg
Add CycleAwareDependencyGraphDumper to visualize cycles
a111ff7
DependencyGraphDumper recurses forever on a graph containing a cycle, and
TreeDependencyVisitor avoids that crash only by hiding every node already
seen anywhere in the graph, cycle or not, so a normal diamond dependency
disappears from the output along with the actual cycle.

CycleAwareDependencyGraphDumper only tracks the path from the root to the
node currently being visited: it prints a node and marks it '(cycle)'
once it reaches an ancestor of itself, instead of descending into it, and
otherwise leaves diamonds fully visible.

Fixing this also exposed a latent bug in formatIndentation(): it picked
out the node currently being formatted by comparing it against
nodes.peekFirst() with ==, which breaks once the same node instance
appears twice in the path, i.e. exactly in a cycle. Comparing by position
in the walk instead fixes it for both dumpers.
gnodet-bot
gnodet-bot approved these changes Oct 28, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No issues found.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@slachiewicz slachiewicz added the enhancement New feature or request label Oct 29, 2026
cstamas
cstamas approved these changes Nov 3, 2026
View reviewed changes
@cstamas cstamas added this to the 2.0.25 milestone Nov 3, 2026
@cstamas
cstamas merged commit c24827b into apache:master Nov 3, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned cstamas Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cstamas cstamas cstamas approved these changes
+1 more reviewer
@gnodet-bot gnodet-bot gnodet-bot approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@cstamas cstamas

Labels

enhancement New feature or request

Projects

None yet

Milestone

2.0.25

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@arturobernalg @cstamas @gnodet-bot @slachiewicz
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.