elharo commented on issue #620:
URL: 
https://github.com/apache/maven-war-plugin/issues/620#issuecomment-4882512176

   On the fix: I chose to fix `hashCode()` rather than `equals()` for the 
following reasons:
   
   1. **`targetFileName` is mutable** — it has a setter and can change after 
construction. Including mutable fields in `equals()`/ `hashCode()` is a 
well-known anti-pattern in Java: if an object is placed in a `HashSet` or 
`HashMap` and then mutated via `setTargetFileName()`, it becomes "lost" in the 
collection because its hash code changed after insertion.
   
   2. **`equals()` was deliberately written without `targetFileName`** — this 
is consistent with the principle that equality should be based on the object's 
identity (the dependency), not its mutable metadata (the output filename).
   
   3. **Minimal, backward-compatible change** — code that already relies on 
`equals()` comparing only `dependency` continues to work unchanged.
   
   If the domain requires that same-dependency/different-target-filename 
objects be treated as distinct, then `equals()` should be changed *and* 
`targetFileName` should be made immutable (removed from the setter). But that 
would be a larger behavioral change than what this bug warrants.


-- 
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]

Reply via email to