gnodet-bot commented on code in PR #13897:
URL: https://github.com/apache/maven/pull/13897#discussion_r4514478271
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultDependencyManagementImporter.java:
##########
@@ -163,6 +168,25 @@ private boolean equals(Exclusion e1, Exclusion e2) {
&& Objects.equals(e1.getArtifactId(), e2.getArtifactId());
}
+ private boolean equalsInclusions(Collection<Inclusion> ci1,
Collection<Inclusion> ci2) {
+ if (ci1.size() == ci2.size()) {
+ Iterator<Inclusion> i1 = ci1.iterator();
+ Iterator<Inclusion> i2 = ci2.iterator();
+ while (i1.hasNext() && i2.hasNext()) {
+ if (!equals(i1.next(), i2.next())) {
+ return false;
+ }
+ }
+ return !i1.hasNext() && !i2.hasNext();
+ }
+ return false;
+ }
+
+ private boolean equals(Inclusion i1, Inclusion i2) {
+ return Objects.equals(i1.getGroupId(), i2.getGroupId())
+ && Objects.equals(i1.getArtifactId(), i2.getArtifactId());
+ }
Review Comment:
⚠️ **`equals(Inclusion)` does not compare the `id` field — deduplication
false negative possible.**
`Inclusion` has an `id` field (the compact `"groupId:artifactId"` form). Two
semantically-identical inclusions — one written as `<id>com.example:lib</id>`
and another as `<groupId>com.example</groupId><artifactId>lib</artifactId>` —
will compare as *unequal* here because `id` is not included in the comparison.
The `match(Inclusion, Dependency)` method correctly resolves `id` before
matching (via `resolveGroupId`/`resolveArtifactId`). The `equals` method should
do the same, or at minimum include `id` in the raw comparison to avoid false
negatives in the importer's deduplication logic.
```suggestion
private boolean equals(Inclusion i1, Inclusion i2) {
return Objects.equals(i1.getGroupId(), i2.getGroupId())
&& Objects.equals(i1.getArtifactId(), i2.getArtifactId())
&& Objects.equals(i1.getId(), i2.getId());
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]