HashSet needs stable hash fields
If an element changes fields used by equals or hashCode while inside a HashSet, contains and remove may fail. Keep identity fields immutable after insertion.
If an element's equals or hashCode inputs change after insertion, the set looks in the wrong bucket and contains or remove can miss it. Make the fields used for identity immutable once stored.
Mutating fields that feed hashCode while an object sits in a HashSet leaves it filed under its old hash. Keeping identity fields final avoids lookups that quietly fail.
Specific and to the point: "HashSet needs stable hash fields". Worth a look if you touch java / hashset.
Hash-based collections assume identity fields are stable, so a mutation after insertion can make an element unfindable. Designing those fields as immutable prevents the problem.
Appreciate the write-up on "HashSet needs stable hash fields". Useful for anyone using java / hashset.
"HashSet needs stable hash fields" is a useful thing to know about with java / hashset. Thanks for sharing it.
Clear note on java / hashset. "HashSet needs stable hash fields" is the kind of detail that is easy to overlook.
Clear note on java / hashset. "HashSet needs stable hash fields" is the kind of detail that is easy to overlook.