Skip to content

Commit 33194cd

Browse files
committed
Document the contract breach of DiffNode.hashCode
1 parent f7bd043 commit 33194cd

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • src/main/java/org/variantsync/diffdetective/diff/difftree

src/main/java/org/variantsync/diffdetective/diff/difftree/DiffNode.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@ public boolean equals(Object o) {
820820
return isMultilineMacro == diffNode.isMultilineMacro && diffType == diffNode.diffType && codeType == diffNode.codeType && from.equals(diffNode.from) && to.equals(diffNode.to) && Objects.equals(featureMapping, diffNode.featureMapping) && lines.equals(diffNode.lines);
821821
}
822822

823+
/**
824+
* Compute a hash using all available attributes.
825+
*
826+
* This implementation doesn't strictly adhere to the contract required by {@code Object},
827+
* because some attributes (for example the line numbers) can be changed during the lifetime of
828+
* a {@code DiffNode}. So when using something like a {@code HashSet} the user of {@code
829+
* DiffNode} has to be careful not to change any attributes of a stored {@code DiffNode}.
830+
*/
823831
@Override
824832
public int hashCode() {
825833
return Objects.hash(diffType, codeType, isMultilineMacro, from, to, featureMapping, lines);

0 commit comments

Comments
 (0)