apache / apache/maven-dependency-tree
SerializingDependencyNodeVisitor holds mutable depth state and is not thread-safe/reentrant
- Dominant language
- Java
- Stars
- 27
- Forks
- 31
- Avg merge
- 5h 53m
- Merged PRs (30d)
- 1
Description
## Summary
`SerializingDependencyNodeVisitor` keeps traversal state in instance fields (`depth`), mutated in `visit(...)`/`endVisit(...)` and read in `getTree(...)`. This makes the visitor neither thread-safe nor safely reentrant:
- Two threads sharing one visitor instance interleave and corrupt the indentation output.
- The same visitor reused for two separate graphs carries stale `depth` between runs.
## Affected code
`src/main/java/org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java`
- `depth` field: line 53
- mutated in `visit(...)`: lines 113-118 and `endVisit(...)`: lines 132-133
- read in `getTree(...)`: lines 89-96
## Impact
`SerializingDependencyNodeVisitor` is the type exposed by `DefaultDependencyNode.getTree(...)`; any caller that reuses or shares the visitor across nodes/threads gets garbled or incorrect output.
## Suggested fix
Make the depth state local to each traversal (e.g. pass a per-run state object through the visitor, or document that each traversal must use a fresh instance), and add a test showing reuse produces correct output.
Contributor guide
No contributing guide indexed for this repository
Research direction
Read src/main/java/org/apache/maven/shared/dependency/graph/traversal/SerializingDependencyNodeVisitor.java, starting with getTree(...), visit(...), and endVisit(...), to trace the depth state across a traversal. Add a regression test showing that reusing the visitor produces correct output, and verify that shared or repeated traversals no longer corrupt indentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100