apache / apache/maven-dependency-tree

DefaultDependencyNode.getChildren() exposes the mutable internal list; class lacks equals/hashCode

Open
#138 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
27
Forks
31
Avg merge
5h 53m
Merged PRs (30d)
1

Description

## Summary
Two API-hygiene problems on `DefaultDependencyNode`:

1. `getChildren()` returns the internal mutable list (`src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java:136-138`). Callers can add/remove/replace children and corrupt the graph. The builders wrap children in `Collections.unmodifiableList` when constructing (`DefaultDependencyCollectorBuilder.java:233`, `DefaultDependencyGraphBuilder.java:161`), so the mutability is mostly incidental — but the `setChildren`/`getChildren` contract leaves the door open, and `BuildingDependencyNodeVisitor` relies on mutating children of the freshly cloned nodes (so it cannot simply be made immutable everywhere without a builder).

2. The class does not override `equals`/`hashCode`. Combined with identity-based comparisons (see the related `AncestorOrSelfDependencyNodeFilter` issue), value-based matching against rebuilt/cloned trees is impossible.

## Suggested fix
Document the mutation contract clearly, or return an unmodifiable view from `getChildren()`; and add value-based `equals`/`hashCode` (e.g. keyed on artifact coordinates) if identity semantics are not intentional.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with DefaultDependencyNode.java at getChildren and setChildren, then inspect the builder call sites in DefaultDependencyCollectorBuilder.java and DefaultDependencyGraphBuilder.java. Read how BuildingDependencyNodeVisitor mutates cloned nodes and review the related AncestorOrSelfDependencyNodeFilter issue before deciding the mutation and equality contracts. Done means the chosen contracts are documented or enforced consistently, with matching hash behavior and tests covering them.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.