apache / apache/maven-war-plugin
DependencyInfo.hashCode() violates equals/hashCode contract
- Dominant language
- Java
- Stars
- 50
- Forks
- 97
- Avg merge
- 16h 49m
- Merged PRs (30d)
- 3
Description
## Bug Description
`DependencyInfo.hashCode()` at `src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java` lines 87-91 violates the equals/hashCode contract.
`equals()` (line 83) compares only the `dependency` field, but `hashCode()` (lines 87-91) incorporates both `dependency` and `targetFileName`.
## Impact
Two `DependencyInfo` objects with the same `dependency` but different `targetFileName` will be `equals()` (return `true`) but produce different hash codes, violating the fundamental contract and causing incorrect behavior in `HashMap`, `HashSet`, or any hash-based collection.
## Code
```java
// equals() — line 83
return Objects.equals(dependency, that.dependency);
// hashCode() — lines 87-91
public int hashCode() {
int result;
result = (dependency != null ? dependency.hashCode() : 0);
result = 31 * result + (targetFileName != null ? targetFileName.hashCode() : 0);
return result;
}
```
## Expected behavior
`hashCode()` should be consistent with `equals()` — either include only `dependency` in both, or include both `dependency` and `targetFileName` in both.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java at equals() and hashCode() lines 83-91, comparing the fields each method uses. Confirm the behavior with equal objects that have different targetFileName values, then run the Maven project tests. Done means equal DependencyInfo objects always return the same hash code for use in HashMap and HashSet.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100