apache / apache/maven-dependency-tree

AncestorOrSelfDependencyNodeFilter uses identity equality and fails on cloned trees

Open
#132 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
`AncestorOrSelfDependencyNodeFilter` matches nodes with `equals(...)`, but the node implementations do not override `equals`/`hashCode`, so the comparison is identity-based. The filter therefore only works when the candidate nodes are the exact same instances as the descendants, and silently matches nothing when applied to a rebuilt tree.

## Affected code
- `src/main/java/org/apache/maven/shared/dependency/graph/filter/AncestorOrSelfDependencyNodeFilter.java:82-92` — `isAncestorOrSelf(...)` compares with `ancestorNode.equals(descendantNode)`
- `src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyNode.java` — no `equals`/`hashCode` override

## Impact
`maven-dependency-plugin` combines this filter with `BuildingDependencyNodeVisitor` (which clones the tree). Because the clone produces different node instances, the ancestor-or-self matches never succeed and the filtered output is empty, even though the graph logically contains the nodes.

## Suggested fix
Implement value-based `equals`/`hashCode` on the node classes (e.g. by artifact coordinates), or compare by artifact in the filter instead of relying on node identity.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading AncestorOrSelfDependencyNodeFilter.java:82-92 and DefaultDependencyNode.java, then trace how BuildingDependencyNodeVisitor clones the tree. Reproduce the filter with rebuilt nodes and compare the result with the original-node case; done means ancestor-or-self matches work on the cloned tree and the filtered output is no longer empty.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.