Skip to content

WarUtils.isRelated() has inverted equality checks for version, type, classifier, scope #619

Description

@elharo

Bug Description

WarUtils.isRelated() at src/main/java/org/apache/maven/plugins/war/util/WarUtils.java lines 69-80 has inverted equality checks. The method returns false when version, type, classifier, or scope are equal between the artifact and the dependency — the opposite of what's intended.

The method should return false only when these attributes differ. As written, the method only returns true if every one of these four attributes differs while groupId/artifactId match.

Impact

This makes registerTargetFileName() in WebappStructure effectively broken: a dependency will never match its artifact when any of these attributes coincide, and could match the wrong dependency when they all differ.

Code

if (Objects.equals(artifact.getVersion(), dependency.getVersion())) {
    return false;  // BUG: should return false when NOT equal
}
if (Objects.equals(artifact.getType(), dependency.getType())) {
    return false;
}
if (Objects.equals(artifact.getClassifier(), dependency.getClassifier())) {
    return false;
}
if (Objects.equals(artifact.getScope(), dependency.getScope())) {
    return false;
}

Expected behavior

Each if block should use !Objects.equals(...) so that false is returned only when the values differ.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions