Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return root node even though everything is filtered. #6846

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am sorry, but this is wrong. I accept that two scopes with different implementation classes but the same name should be equal, but then please do something like:

if (!(obj instanceof Scope)) {
    return false;
}

I believe generally equals is expected to not crash on CCEs, even if an object of an unrelated type is passed in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh oh ... mea culpa. Of course.

if (!(obj instanceof Scope)) {
return false;
}
final Scope other = (Scope) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ private void findRealNodes(org.apache.maven.shared.dependency.tree.DependencyNod
private Dependency convertDependencies(org.apache.maven.shared.dependency.tree.DependencyNode n, Dependency.Filter filter, Set<ArtifactSpec> broken) {
Map<String, List<org.apache.maven.shared.dependency.tree.DependencyNode>> realNodes = new HashMap<>();
findRealNodes(n, realNodes);
return convert2(n, filter, realNodes, broken);
return convert2(true, n, filter, realNodes, broken);
}

private Dependency convert2(org.apache.maven.shared.dependency.tree.DependencyNode n, Dependency.Filter filter, Map<String, List<org.apache.maven.shared.dependency.tree.DependencyNode>> realNodes, Set<ArtifactSpec> broken) {
private Dependency convert2(boolean root, org.apache.maven.shared.dependency.tree.DependencyNode n, Dependency.Filter filter, Map<String, List<org.apache.maven.shared.dependency.tree.DependencyNode>> realNodes, Set<ArtifactSpec> broken) {
List<Dependency> ch = new ArrayList<>();

List<org.apache.maven.shared.dependency.tree.DependencyNode> children = null;
Expand All @@ -286,7 +286,7 @@ private Dependency convert2(org.apache.maven.shared.dependency.tree.DependencyNo
}

for (org.apache.maven.shared.dependency.tree.DependencyNode c : children) {
Dependency cd = convert2(c, filter, realNodes, broken);
Dependency cd = convert2(false, c, filter, realNodes, broken);
if (cd != null) {
ch.add(cd);
}
Expand All @@ -303,7 +303,7 @@ private Dependency convert2(org.apache.maven.shared.dependency.tree.DependencyNo
}
Scope s = scope(a);

if (!filter.accept(s, aspec)) {
if (!root && !filter.accept(s, aspec)) {
return null;
}

Expand Down